ferror

From RAD Studio
Jump to: navigation, search

Go Up to stdio.h Index


Header File

stdio.h

Category

Input/output Routines

Prototype

int ferror(FILE *stream);

Description

Detects errors on stream.

ferror is a macro that tests the given stream for a read or write error. If the stream's error indicator has been set it remains set until clearerr or rewind is called or until the stream is closed.

Return Value

ferror returns nonzero if an error was detected on the named stream.

Example

#include <stdio.h>
int main(void)
{
   FILE *stream;
   /* open a file for writing */
   stream = fopen("DUMMY.FIL", "w");
   /* force an error condition by attempting to read */
   (void) getc(stream);
   if (ferror(stream))  /* test for an error on the stream */
   {
      /* display an error message */
      printf("Error reading from DUMMY.FIL\n");
      /* reset the error and EOF indicators */
      clearerr(stream);
   }
   fclose(stream);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+

+

+

+