Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic


Resets the error indicator for a stream. This is a version of clearerr with security enhancements as described in Security Enhancements in the CRT.

errno_t clearerr_s(
   FILE *stream 



Pointer to FILE structure

Zero if successful; EINVAL if stream is NULL.

The clearerr_s 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_s, 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 EINVAL.

Routine Required header Compatibility



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_s.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;
   errno_t err;

   // Create an error by writing to standard input.
   putc( 'c', stdin );
   if( ferror( stdin ) )
      perror( "Write error" );
      err = clearerr_s( stdin );
      if (err != 0)

   // See if read causes an error.
   printf( "Will input cause an error? " );
   c = getc( stdin );
   if( ferror( stdin ) )
      perror( "Read error" );
      err = clearerr_s( stdin );
      if (err != 0)



Sample Output

Write error: Bad file descriptor
Will input cause an error? n

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.