Skip to main content
C Code Reorder Hard +35 XP

File Write Pattern

Arrange to safely write to a file.

Click lines in the correct order

Available lines4 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: FILE *fp = fopen("out.txt", "w"); if (!fp) return 1; fprintf(fp, "Hello\n"); fclose(fp);

Open, check for NULL, write, then close. Always close files when done.

Hint: Open then check, write, then close.

What this challenge tests

Code Reorder in C: file-io, fopen.

Related challenges