This post was published long ago, when I was a student and an amateur blogger. The links might be broken and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART -B
………………………………………………………………………………………………………………………….
- b) C program to create a file with 16 bytes of arbitrary data from the beginning and another 16 bytes of arbitrary data from an offset of 48. Display the file contents to demonstrate how the hole in file is handled.
……………………………………………………………………………………………………………………………
#include<stdio.h>
#include<unistd.h>
main()
{
FILE *fp;
int i,j;
char ch;
fp=fopen(“text.txt”,”w”);
ch=’a’;
for(i=o;i<16;i++)
{
fwrite(&ch,1,1,fp);
ch++;
}
fseek(fp,48L,1);
ch=’A’;
for(j=0;j<16;j++)
{
fwrite(&ch,1,1,fp);
ch++;
}
fclose(fp);
fp=fopen(“text.text”,’r”);
while((fread(&ch,1,1,fp))!=0)
print(“%c”,ch);
fclose(fp);
}
[Request : If you are going to post this program on any other website please link back to original post ]
Leave a ReplyCancel reply