> ferror<STDIO.H> ~ Online tutorial

ferror



ferror  <STDIO.H>

 Macro that tests if an error has occurred on a stream

 Declaration:

int ferror(FILE *stream);


 Remarks:


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 non-zero 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;
 }

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: