...
The following scenarios will be diagnosed because either can result in undefined behavior: • Receiving
- Receiving input from a stream directly following an output to that stream without an intervening call to
fflush,fseek,fsetpos, orrewindif the file is not at end-of-file
...
- Outputting to a stream after receiving input from that stream without a call to
fseek,fsetpos, orrewindif the file is not at end-of-file
(See also undefined behavior 151 in Annex J of C11.) Consequently, a call to fseek(), fflush(), or fsetpos() is necessary between input and output to the same stream. (See FIO07-C. Prefer fseek() to rewind().)
...