[Previous] [Contents] [Next]

ferror()

Test a stream's error flag

Synopsis:

#include <stdio.h>

int ferror( FILE* fp );

Library:

libc

Description:

The ferror() function tests the error flag for the stream specified by fp.

Returns:

0 if the error flag isn't set, or nonzero if the error flag is set.

Examples:

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

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

    fp = fopen( "file", "r" );
    if( fp != NULL ) {
        c = fgetc( fp );
        if( ferror( fp ) ) {
            printf( "Error reading file\n" );
        }
    }
    fclose( fp );
    
    return EXIT_SUCCESS;
}

Classification:

ANSI

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

See also:

clearerr(), feof(), perror(), strerror()


[Previous] [Contents] [Next]