One area that is often overlooked in various texts that describe the stdio(3) set of routines is the proper treatment of errors. You have already seen how to discriminate between an error return and a success return with the fopen(3) call. Immediately after a fopen(3) failure, the value of errno contains the reason for the open failure. However, the situation may not be so clear in other circumstances, which will be examined next.
By way of review, examine the function synopsis for the ferror(3) function:
#include <stdio.h> int ferror(FILE *stream); /* Test stream for an error */ void clearerr(FILE *stream); /* Clear an error indication */
The ferror(3) function returns a ...