Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Resets the error indicator for a stream. A more secure version is available; see clearerr_s.

void clearerr(
   FILE *stream 



Pointer to FILE structure.

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.

If stream is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, this function sets errno to EINVAL and returns. For more information on errno and error codes, see errno Constants.

A more secure version of this function is available; see clearerr_s.

Routine Required header Compatibility



ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// 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 );
      printf( "No read error\n" );



Sample Output

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

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

© 2015 Microsoft