In various examples found on the web fgetc()
is used like this:
FILE *fp = fopen(PATH, "r");
if (fp == NULL) {
perror("main");
exit(EXIT_FAILURE);
}
int ch;
while (ch = fgetc(fp) != EOF) {
// do something
}
But according to the manpage to fgetc()
If a read error occurs, the error indicator for the stream shall be set, fgetc() shall return EOF, [CX] and shall set errno to indicate the error.
So need I check this too? And how?