0
Writing into a binary file in C
I have a structure: struct Date{ int day; int month; int year; }array[100]; I need to write into a binary file so that the day and the month are written into a file taking 1 byte each (I figured I'll use unsigned char) and the year taking 2 bytes(unsigned short). What is the easiest way to do that? I tried something like this: https://code.sololearn.com/cE4vukzJkt2B/?ref=app But it does not work as it should. What is the usual way to write the required number of bytes into a binary file?
3 Answers
0
If you want an answer, it is best to share a link to the code you used. What you shared will not compile. If the code is not in the playgound, place it there. You can use the plus within the circle icon to include a link or copy & paste it.
Hit the icon, select insert code, change hot today to my code bits, select the code, and hit the done to insert the link.
Enter the program, hit the share icon, select the copy to clipboard, come back here, press an hold a second, and select paste.
0
John Wells I can not copy my code because it is a part of my assignment. Thank you for the tips. Perhaps I should edit my question to be more straight to the point.
0
How about sharing the assignment. That should help make sense of the code fragment as it should mention the requirements to the interface. The code you create can be shared even if it is only a part of the whole.