Archived

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

GekkoCube

memsetting a structure.

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