Challenge 1: Writing Three Lines, Then Reading Them Back — Possible Solution ==================================================================== #include int main() { FILE *out = fopen("lines.txt", "w"); if (out == NULL) { return 1; } fprintf(out, "first line\n"); fprintf(out, "second line\n"); fprintf(out, "third line\n"); fclose(out); FILE *in = fopen("lines.txt", "r"); if (in == NULL) { return 1; } char line[256]; while (fgets(line, sizeof(line), in) != NULL) { printf("%s", line); } fclose(in); return 0; } Output: first line second line third line WHY THIS WORKS AS AN ANSWER ------------------------------ The write handle is fully closed with fclose before the file is reopened for reading -- flushing the buffered writes to disk first, as the chapter describes -- and fgets is used with an explicit buffer size (sizeof(line)) rather than an unbounded read, exactly the safe pattern the chapter contrasts against the removed gets().