Mail Archives: djgpp/1997/07/13/06:22:59
Deltaman (deltaman AT swipnet DOT se) wrote:
: Hi!
: I have a program, sort of an editor. Its data structures is like this:
<snip>
: 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");
<snip>
: void read_board (map *b, char *fname)
: {
: FILE *f;
: f = fopen (fname, "r");
^^^
: fwrite (b->data, sizeof (my_struct), mapx * mapy, f);
^^^^^^
<snip>
Firstly, the read_board() does not open the file in binary mode, probably
your bug. Secondly, it calls fwrite() when it seems to me if it is
intended to read it might work a little bit (!!) better if you called
fread() instead!
Fred
--
---- Fred Smith -- fredex AT fcshome DOT stoneham DOT ma DOT us -- fred AT computrition DOT com ----
"And he will be called Wonderful Counselor, Mighty God, Everlasting Father,
Prince of Peace. Of the increase of his government there will be no end. He
will reign on David's throne and over his kingdom, establishing and upholding
it with justice and righteousness from that time on and forever."
------------------------------- Isaiah 9:7 (niv) ------------------------------
- Raw text -