Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ferror - Test for file error

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int ferror(FILE *fp);

ferror checks whether the error flag is set in the FILE structure to which fp points.

Return val.

!= 0

0

An error flag is set.

No error flag is set.

Notes

ferror is implemented both as a macro and as a function (see section “Functions and macros”).

The error flag remains set until the associated file pointer is released (e.g. by fclose or
program termination) or until the clearerr function is called.

You should always use ferror when you want to read from a file or write to it.

Record I/O

Example

ferror can also be used unchanged on files with record I/O.

The following program fragment checks before each fread call whether an error has been
indicated for the FILE structure pointed to by fp.

FILE *fp;
char buf[10];
char x[5];
while( !ferror(fp))
     fread(buf,sizeof(x),10,fp);

See also

clearerr, feof, fopen, fopen64