Open a file in append mode in C

# include <stdio.h>
# include <conio.h>
# include <process.h>
 
void main()
{
   FILE *fp;
   char c=' ';
   clrscr();
   fp=fopen("mydata.txt","a+");
   if(fp==NULL)
   {
	  printf("Can not open file");
	  exit(1);
   }
   printf("Press '.' to exit:");
   while(c!='.')
   {
	  c=getche();
	  fputc(c,fp);
   }
   printf("\n Contents read :");
   rewind(fp);
   while(!feof(fp))
   printf("%c",getc(fp));
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.