Newsgroups: comp.os.msdos.djgpp From: fredex AT fcshome DOT stoneham DOT ma DOT us (Fred Smith) Subject: Re: My structures get broken when I fwrite Organization: None! Message-ID: References: <33C76A7A DOT 15E4 AT swipnet DOT se> Date: Sat, 12 Jul 1997 19:54:40 GMT Lines: 39 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Deltaman (deltaman AT swipnet DOT se) wrote: : Hi! : I have a program, sort of an editor. Its data structures is like this: : 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"); : void read_board (map *b, char *fname) : { : FILE *f; : f = fopen (fname, "r"); ^^^ : fwrite (b->data, sizeof (my_struct), mapx * mapy, f); ^^^^^^ 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) ------------------------------