When you fwrite
to a file, it may not actually write anything, it may stay in a buffer (inside the FILE object). Calling fflush
would actually write it to disk. That operation may fail, for example if you just ran out of disk space, or there is some other I/O error.
fclose
flushes the buffers implicitly too, so it may fail for the same reasons.