Name

ferror

Synopsis

Tests whether a file access error has occurred

#include <stdio.h>
intferror( FILE *fp );

The ferror() function—often implemented as a macro—tests whether an error has been registered in reading or writing a given file.

ferror()’s argument is a FILE pointer. One attribute of the file or stream referenced by this pointer is an error flag which indicates that an error has occurred during a read or write operation. The ferror() function or macro tests the error flag and returns a nonzero value if the flag is set. If not, ferror() returns 0.

Example

See the examples for clearerr() and fclose() in this chapter.

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.