Mega Code Archive

 
Categories / C / Code Snippets
 

Check for errors How to use ferror

#include <stdio.h> int main () { FILE *file; file = fopen("myfile.txt","r"); if (file==NULL) perror ("Error opening myfile.txt"); else { fputc ('e',file); if (ferror (file)) printf ("Error Writing to myfile.txt\n"); fclose (file); } return 0; }