...
This compliant solution uses ferror()
to detect an error. In addition, if an early call to printf()
fails, later ones calls may modify errno
whether they fail or not, so the program cannot rely on being able to detect the root cause of the first original failure if it waits until after a sequence of library calls to check.
...