Jump to content
  • Advertisement


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


memsetting a structure.

This topic is 5220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class with some simple members in it, let''s call the class Address, and let''s say it has members: name, street, zipcode, phonenumber. now if i want to read in this class from a binary file, should i create an Address from a pointer, or should i leave it as a pointer and then read it in using fread? And how can i initialize a structure using memset?

Share this post

Link to post
Share on other sites
well, i''ve seen past posts about this very topic, but it doesnt work for me....perhaps the poster was wrong?

class Address
char *name;
int number;
int zip;

Address addr;
memset(&addr, 0, sizeof(Address));
// print out member variables here.

I think this should initialize all member variables in Address.
But it doesnt.
what am i missing?

Share this post

Link to post
Share on other sites
wow, three consecutive posts by me.
this is my new record!

i found out why it didnt work.
i wasnt writing one of the members to the file, then when i read it back i used memset, but i was reading in a member that wasnt initialized before it was written to file.

so, i used memset before i write as well.
this was my problem.

thanks. thread closed.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!