what is wrong with this way in saving struct...,
Code:
typedef struct _INFO
{
char *id;
int height, width;
}INFO;
void Save()
{
INFO info;
char id[] = "hello";
info.id = new char[sizeof(id)];
// filling the structure
strcpy(map.id, id);
info.width = 640;
info.height = 480;
// saving routine
ofstream saveinfo;
saveinfo.open("info.dat", ios::binary);
saveinfo.write((const char *)&info, sizeof(info));
okey when i tried to read this struct, i get garbage on the id part... why?
thanks,
Re: what is wrong with this way in saving struct...,
Quote:
Originally posted by mickey
okey when i tried to read this struct, i get garbage on the id part... why?
Which struct variable, map or info?
Why did ya do this:
Code:
info.id = new char[sizeof(id)];
// filling the structure
strcpy(map.id, id);
Is that what you meant to do, or is it a typo?