Reputation: 146
I have a program which simulates the orbits of planets. The information for each time step is written to a .txt
file with each iteration requiring 64 bytes of memory (8 doubles
). The time step is chosen by the user and the final time is chosen by the user. This allows me to calculate the amount of memory required on the disk. E.g, a step of 10 with a final time of 1000 gives 100 set of info, implying at least 6400 bytes of memory.
Is there a way of using this information to, for lack of a better word, check the drive to see if there is enough space before allowing the program write to the file, as i would like to prevent files which are too large from being written to disk. Ideally this should be standard C if possible.
Upvotes: 1
Views: 61
Reputation: 7996
If you know in advance exactly how much space you need, you can try for all the needed files:
In case of error when fflush'ing, remove all files.
When you're finished, fclose the files.
Upvotes: 1