A few hints (not a complete solution):
The fact that tm->tm_mon
is zero-based and thus requires +1
to make sense as a month number jan…dec, does not mean that you must write sizeof(tm->tm_mon+1)
.
In the same way, if you want to write its value and take its address, that does not mean you have to add 1. Think what you are doing: to what are you adding this 1??? (just as think about what you were taking the size of.)
And if you want to write this value, then do not mix a function like printf
which requires a format string (the f
meaning “print formatted”) with fwrite
(the f
meaning File Write). Thus you don’t provide a format string with what you want to write, you just provide the address of what needs to be written. And of course without any +1 (what would you be adding this 1 to?)
With these hints I hope you can find your answer. And remember, If nothing helps, Read the Manual!
3
solved How to write data to a binary file using C