Archived

This topic is now archived and is closed to further replies.

Mansion

struct and binary file

Recommended Posts

hello how do i write like typedef tagplayer{ int x, y; }player; to a binary file and how to read it, with fprintf it doesnt go smooth... thank you

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"better" is in the eye of the beholder. tagplayer is unlikely to have any padding so the effort to eliminate it is wasted.

Even if padding was there, your first example (single fwrite) has less code and is arguably easier to understand. Also, copying whole structures with a single memcpy can be faster than copying every member individually even taking the padding into account.

-Mike

Share this post


Link to post
Share on other sites