|
(Solved!) Problem reading struct from file [fread, struct, fopen, rb] August 07, 2009 04:24PM | Registered: 16 years ago Posts: 10 |
typedef struct
{
char stav_pohybu;
char stav_aktivace;
char pozice40[2];
char pozice41[2];
int pozice800[2];
int g_size[2];
int g_ani_start[2];
int g_ani_curr[2];
int g_ani_orient;
char g_ani_frame;
char g_ani_speed;
char g_ani_poc;
int g_ani_framemax;
int g_ani_posun[30][2];
char poc;
} Tactors;
Tactors ac[2]; // << here I want to load data
void load_room_object_data(int room)
{
char* FileName = "data/rooms/object.dat"; // File exists, I am sure
FILE* File = NULL;
File = fopen(FileName, "rb");
long size_ac = sizeof(ac);
fseek(File, room*(size_ac),SEEK_SET);
fread (&ac, size_ac, 1, File); // << here is reading from file
fclose(File);
}|
Re: Problem reading struct from file [fread, struct, fopen, rb] August 07, 2009 06:07PM | Registered: 17 years ago Posts: 703 |
int swap4 (int n)
{
return (((n&0x000000FF)<<24)+((n&0x0000FF00)<<8)+((n&0x00FF0000)>>8)+((n&0xFF000000)>>24));
}
void load_room_object_data(int room)
{
char* FileName = "data/rooms/object.dat"; // File exists, I am sure
FILE* File = NULL;
File = fopen(FileName, "rb");
long size_ac = sizeof(ac);
fseek(File, room*(size_ac),SEEK_SET);
fread (&ac, size_ac, 1, File); // << here is reading from file
fclose(File);
// for all int values do the following ... e.g
ac.g_ani_framemax = swap4(ac.g_ani_framemax);
}