What you will learn
Write, rewind and read a temporary file.
Understand the concept
FILE represents a stream managed by the C library. tmpfile opens a temporary binary update stream, removed when closed. Check whether opening, writing and reading succeed. rewind moves the position to the beginning so that the program can read back its data. Some hosted compilers restrict filesystem access.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
Repair ready
Practise
Write two lines, rewind, and read them using a loop around fgets.
Common mistake
Always check the file pointer before using it. Reading a file changes its current position; it does not automatically start over.
