Open file for read/write operation in binary mode

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

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.