-
Okay, I can figure out how to print out a string with the time information, but what about storing it in a binary file specifically for the purpose of pulling it out to do calculations with?
Do I just do a fwrite with the tm pointer or something like that?
-
Split from old post
Sure you can fwrite and fread it, but its a very non-portable way of doing it.
-
>> Do I just do a fwrite with the tm pointer or something like that?
Well, fwrite()'ing pointer to *anything* won't ever work.
time_t is just a typedef for a certain size of int (the size being dependant on the system).
A portable way to do it would be:
time_t stamp;
//...stuff
fwrite(&stamp, 1, sizeof(time_t), out);
-
>time_t is just a typedef for a certain size of int
No. A time_t is an arithmetic type, which includes integer and floating types.
The method you've shown isn't portable between implementations that represent time_t differently.
[edit]
By that I mean that if the file was written with representation A but read with representation B, and vice-versa, the results might be unexpected. This could be so even from the same source code built on different implementations.
[/edit]