Reset error indicators: writing errors : error « Development « C / ANSI-C






Reset error indicators: writing errors


#include <stdio.h>

int main ()
{
  FILE * pFile;
  pFile = fopen("f.txt","r");

  if (pFile==NULL) 
      perror ("Error opening file");
  else {
      fputc ('v',pFile);
      if (ferror (pFile)) {
          printf ("Error Writing to f.txt\n");
          clearerr (pFile);
      }
      fgetc (pFile);
      if (!ferror (pFile))
          printf ("No errors.\n"); 
      fclose (pFile);
  }
  return 0;
}


           
       








Related examples in the same category

1. Print error message: how to use perror
2. Get pointer to error message string: how to use strerror
3.Define Macro for string variable
4.Preprocessor: error
5.Preprocessor: line