[Previous] [Contents] [Next]

clearerr()

Clear a stream's end-of-file and error flags

Synopsis:

#include <stdio.h>

void clearerr( FILE *fp );

Library:

libc

Description:

The clearerr() function clears the end-of-file and error flags for the stream specified by fp.

These indicators are also cleared when the file is opened, or by an explicit call to clearerr() or the rewind() function.

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    FILE *fp;
    int c;

    c = 'J';
    fp = fopen( "file", "w" );
    if( fp != NULL ) {
      fputc( c, fp );
      if( ferror( fp ) ) {  /* if error        */
          clearerr( fp );   /* clear the error */
          fputc( c, fp );   /* and retry it    */
      }
    }

    fclose( fp );

    return EXIT_SUCCESS;
}

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

feof(), ferror(), fopen(), perror(), rewind()


[Previous] [Contents] [Next]