Mail Archives: djgpp/1997/07/12/07:33:19
Hi!
I have a program, sort of an editor. Its data structures is like this:
#define mapx 20
#define mapy 15
typedef struct {
int type;
int back;
int attr;
} my_struct;
typedef struct {
my_struct data [mapx][mapy];
} map;
When I fill the structures with data it works OK, but when I save a map
and reload it it get broken. About half of the data gets lost/corrupted.
These are the functions I use to read/write data:
void save_board (map *b, char *fname)
{
FILE *f;
f = fopen (fname, "wb");
fwrite (b->data, sizeof (my_struct), mapx * mapy, f);
fclose (f);
}
void read_board (map *b, char *fname)
{
FILE *f;
f = fopen (fname, "r");
fwrite (b->data, sizeof (my_struct), mapx * mapy, f);
fclose (f);
}
I know the data is correct before saving it, so I guess something in
these functions must be wrong. Can any kind soul please help me. TIA!
--
Deltaman (deltaman AT swipnet DOT se)
http://www.geocities.com/TimesSquare/8240
- Raw text -