Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this compliant solution, buf is set to an error message after empty string if fgets fails.

Code Block
bgColor#ccccff
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);

...