fseek(data, header.offsetFrames, SEEK_SET);
fread(frames, sizeof(frame), header.numFrames, data);
frames is the variable to store the info, and frame is the structure name. Now, I think the problem is that the since the structure holds a pointer and not an actual array, the sizeof doesn''t return the right size. I''ve tried a number of different sizeof() combinations, but nothing is working. Is there any way to do what I''m trying to do? Does this make sense?
reading binary files
I''m having a little trouble here reading from a binary file (.md2 specifically). I''m using C style I/O here.
I have a structure to hold the frame information, and inside the frame information I have an unknown sized array which will be dynamically created before reading from the file. The trouble I''m having though is that the structure is being filled correctly, except for the array I created. Here''s what I''m using now:
Since you''re array will be dynamic, then you''ll have to store the size of the array saved int the file somewhere in the file. Sorta like this:
Hope that helps.
typedef struct{ int framex; int framey; ... (whatever) int ArraySize; int *Array;} tFrame;tFrame Frame1;// saving to filefwrite(&Frame1, sizeof(tFrame) - sizeof(int *), fOutput);fwrite(Frame1.Array, sizeof(int), Frame1.ArraySize, fOutput);// loading from filefread(&Frame1, sizeof(tFrame) - sizeof(int *), fInput);fread(Frame1.Array, sizeof(int), Frame1.ArraySize, fInput);
Hope that helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement