ferror() Test for Error on a Stream (Macro)
#include <stdio.h>
int ferror(stream);
FILE *stream; Pointer to file structure
ferror() is a macro that tests for reading or writing errors in
'stream'. If an error has occurred, the stream's error indicator
remains set until rewind() or clearerr() is called or until the
stream is closed.
Returns: Zero if no error has occurred. A non-zero value
indicates an error.
-------------------------------- Example ---------------------------------
The following statements open a file and check for reading errors.
#include <stdio.h>
FILE *in;
char str[50], *nstr;
main()
{
if ((in = fopen("text.dat","r+")) != NULL) {
.
.
nstr = fgets(str,50,in);
if (ferror(in)) {
printf("read error\n");
clearerr(in);
}
}
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster