Help! XL save file

Started by
1 comment, last by Xgkkp 22 years, 2 months ago
ok, i am writing a gta style game, and i am trying to set up a system to save the city data. my city is in a 256x256x7 array of classes (next thing on list is to change to array of pointers to classes) When i save, i save a 30k header(ish) and then call each block in turn to save itself. this creates a 527mb file? each fwrite is returning 36 as the bytes written. is it me, or should it only be taking 15 megabytes? ((256*256*7)/1024)/1024 code of writing: struct boxstorage { //Textures int TopTex; int ScreenTopTex; int ScreenBotTex; int LeftTex; int RightTex; //draw bool exists; //Colours float r, g, b; } thisbox; thisbox.TopTex = TopTex; . .(others) . thisbox.b = b; return fwrite ( &thisbox, sizeof(boxstorage), sizeof (boxstorage), (FILE*)Filehandle );
Advertisement
fwrite() returns the number of full items written, which is sizeof(boxstorage) in your case (the error). The third parameter of fwrite() is not how many bytes to write, but how many items to write, so if you only want to write the structure once then move on to the next then you should set the third parameter to 1.

Invader X
Invader''s Realm
THANKS!!!!!! The math works out exactly right for writing each one 36 times. This should also explain a problem i've had with fread in which the Call Stack is mysteriously resetting, causing a crash when the function exits.

Edited by - Xgkkp on February 8, 2002 3:36:16 AM

This topic is closed to new replies.

Advertisement