clearerr -- Reset Error Indicators

Format

#include <stdio.h>
void clearerr (FILE *stream);

Language Level: ANSI, POSIX, XPG4
The clearerr function resets the error indicator and end-of-file indicator for the specified stream. Once set, the indicators for a specified stream remain set until your program calls clearerr or rewind. fseek also clears the end-of-file indicator.

Return Value
There is no return value.

Example
This example reads a data stream and then checks that a read error has not occurred.

#include <stdio.h>
#include <stdlib.h>
FILE *stream;
int c;
#if (1 == __TOS_OS2_)
   #define FILENAME "myfile.dat"     /* OS/2 file name */
#if (1 ==__TOS_WIN_)
   #define FILENAME "myfile.dat"  /* Windows file name */
#endif
int main(void)
{
   if (NULL != (stream = fopen("FILENAME, "r"))) {
      if (EOF == (c=getc(stream))) {
         if (feof(stream)) {
            perror("Read error");
            clearerr(stream);
         }
      }
   }
   return 0;
   /*****************************************************
      If FILENAME is an empty file,
      the output should be:
      Read error: Attempted to read past end-of-file.
   *****************************************************/
}


feof -- Test End-of-File Indicator
ferror -- Test for Read/Write Errors
perror -- Print Error Message
rewind -- Adjust Current File Position
strerror -- Set Pointer to Runtime Error Message
_strerror -- Set Pointer to System Error String
<stdio.h>