ProAnswers.org

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

#include

#include 

#include 

void main() 

{ 

FILE *fp; 

char c=‟ „; 

clrscr(); 

fp=fopen(“data.txt”, “r+”); 

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); 

} 

getch(); 

} 

Output: 

Contents read: Help me. 

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