...
The following scenarios can result in undefined behavior 151:
- Receiving input from a stream directly following an output to that stream without an intervening call to
fflush()
,fseek()
,fsetpos()
, orrewind()
if the file is not at end-of-file - Outputting to a stream after receiving input from that stream without a call to
fseek()
,fsetpos()
, orrewind()
if the file is not at end-of-file
...
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().)
Noncompliant Code Example
...