Using the value of a pointer to a FILE
object after the associated file is closed is undefined behavior. (See undefined behavior 148153.) Programs that close the standard streams (especially stdout
but also stderr
and stdin
) must be careful not to use these streams in subsequent function calls, particularly those that implicitly operate on them (such as printf()
, perror()
, and getc()
).
...
[IEEE Std 1003.1:2013] | XSH, System Interfaces, open |
[ISO/IEC 9899:20112024] | Subclause 7.2123.3, "Files" |
...