ProAnswers.org

Write a C program to open a file for read/write operation in binary mode. Read and Write new information in the file?

#include

#include



#include



void main()



{



FILE *fp;



char c=‟ „;



clrscr();



fp=fopen(“data.dat”, “wb”);



if(fp= = NULL)



{



Printf(“cannot open file”);



exit(1);



}



Printf(“

Contents read:”);

While(!feof(fp))



Printf(“%c” getc(fp));



Printf(“write data & to stop press „.‟ :”);



while(c=‟!‟)



{



C=getche();



fputc(c,fp);



}



fclose(fp);



fp=fopen(“data.dat”, “rb”);



printf(“

contents read:”);

while(!feof(fp))



printf(“%c”, getc(fp));



getch();



}



[b]Output: [/b]



Contents read: Help me.



Write data & to stop press‟.‟: I am in trouble.