I am using the fopen()
function open a file to write, and return a FILE
pointer. I then use this pointer with fprintf()
, but data doesn\'t
You either need to call fflush(), or just fclose() the file when you're done writing to it. fclose()
will attempt to flush before closing. This behavior is a part of ISO C and POSIX so you can rely on it. See here for more information about fclose()
:
Flushes a stream, and then closes the file associated with that stream. Afterwards, the function releases any buffers associated with the stream. To flush means that unwritten buffered data is written to the file, and unread buffered data is discarded.
If you keep writing to a file and never flush or close it, the OS will start flushing data to the file "when it's ready to", after enough writes are queued up.