Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
div
Expand Minimize

clearerr

Resets the error indicator for a stream.

void clearerr(
   FILE *stream 
);

Parameter

stream
Pointer to FILE structure.

Remarks

The clearerr function resets the error indicator and end-of-file indicator for stream. Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr, fseek, fsetpos, or rewind is called.

Requirements

Routine Required header Compatibility
clearerr <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_clearerr.c
/* This program creates an error
 * on the standard input stream, then clears
 * it so that future reads won't fail.
 */

#include <stdio.h>

int main( void )
{
   int c;
   /* Create an error by writing to standard input. */
   putc( 'c', stdin );
   if( ferror( stdin ) )
   {
      perror( "Write error" );
      clearerr( stdin );
   }

   /* See if read causes an error. */
   printf( "Will input cause an error? " );
   c = getc( stdin );
   if( ferror( stdin ) )
   {
      perror( "Read error" );
      clearerr( stdin );
   }
}

Input

n

Sample Output

Write error: No error
Will input cause an error? n

See Also

Error Handling Routines | Stream I/O Routines | _eof | feof | ferror | perror | Run-Time Routines and .NET Framework Equivalents

Show:
© 2015 Microsoft