| Previous | Home | Next |
Description
The C library function, The ferror () function tests if an error has occured in the file.
Declaration
Following is the declaration for ferror() function.
int ferror(FILE *stream)
Parameters
stream - The stream whose error indicator is to be tested.
Return Value
The ferror function returns 0 if no error has occurred and returns nonzero if an error has occurred.
Example
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f;
if((f=fopen("test", "rb"))==NULL)
{
printf("Cannot open file.\n");
exit(1);
}
putc('C', f);
if(ferror(f)) {
printf("File Error\n");
exit(1);
}
fclose(f);
return 0;
}
Output
File Error
| Previous | Home | Next |