...
In this compliant solution, buf is set to an error message after empty string if fgets fails.
| Code Block | ||
|---|---|---|
| ||
enum { BUFFERSIZE = 1024 };
char buf[BUFFERSIZE];
FILE *file;
/* Initialize file */
if (fgets(buf, sizeof(buf), file) == NULL) {
/* set error flag and continue */
strcpy(*buf, "fgets failed")= '\0';
}
printf("Read in: %s\n", buf);
|
...