Enter your email address & Win:

System Software Lab Programs ( UNIX Programs ) – 2b

// March 6th, 2009 // Engineering, Unix and System Software Lab // Written by

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

………………………………………………………………………………………………………………………….
PART -B

………………………………………………………………………………………………………………………….

2. 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 ]


If you enjoyed this post, make sure you subscribe to my RSS feed!

Get Adobe Flash playerPlugin by wpburn.com wordpress themes