| cplusplus.com > reference > cstdio > clearerr | 
| 
clearerr
 <stdio.h>  | 
| cplusplus.com | 
 Reset error indicators.
 
Reset error and EOF indicators of the given stream.
 
After an error occurs using a stream these indicators are not automatically reset to
their initial values until this, rewind(),
fseek() or fsetpos()
functions are called.
Parameters.
 Return Value.
 
None
 Example.
/* writing errors */
#include <stdio.h>
int main ()
{
  FILE * pFile;
  pFile = fopen("myfile.txt","r");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    fputc ('x',pFile);
    if (ferror (pFile))
      {
      printf ("Error Writing to myfile.txt\n");
      clearerr (pFile);
      }
    fgetc (pFile);
    if (!ferror (pFile))
      printf ("No errors reading myfile.txt\n"); 
    fclose (pFile);
  }
  return 0;
}
This program opens a existing file called myfile.txt
and causes an I/O error. That error is cleared using clearerr
so a second error checking returns false.
Output:
 Error Writing to myfile.txt
 No errors reading myfile.txt
 See also.
 
feof,
ferror,
fwrite