creating a logfile
hi, I''m trying to create a logfile in my game by simply using fprintf and outputing strings to a file.
The main reason i''m doing this is to debug some parts of my network code to make sure that what i want to be sent is being sent.
The problem I have is that if the program exits because of an error the logfile is left blank. It works fine when the program exits normally.
Any help would be appreciated.
Even better:
What does it do? It sets the specified filestream to be unbuffered, meaning its data is immediately written to disk.
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
setvbuf(fp, NULL, _IONBF, 0);
What does it do? It sets the specified filestream to be unbuffered, meaning its data is immediately written to disk.
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
If it''s completely blank, you''re probably not even calling fclose(). Everything will be flushed when you close the file. However, as was already suggested, you should also use fflush() occasionally in case you''re program crashes (in which case fclose() is definitely never called, and you''re logfile is blank).
But if you use stvbuf, you don''t have to call fflush and you can let the program crash all it wants to. The data will be there in the log file.
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement