codescracker


c

C ferror()



« Previous Function Next Function »


ferror()

The ferror() function is used to check for the file error on given stream. A return value of zero indicates no error has occurred, whereas a non-zero value indicates an error occurred.

ferror() Syntax

Following is the syntax of the ferror() function:

#include<stdio.h>
int ferror(FILE *stream);

Note : Use perror to determine the exact nature of error

ferror() Example

The following c program aborts program execution if a file error occurs ( Let's assume that fp points to a stream that opened fro write operations ) :

while(!done)
{
	putc(info, fp);
	if(ferror(fp))
	{
		printf("File Error..!!\n");
		printf("Press any key to exit..\n");
		getch();
		exit(1);
	}
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test