Message-ID: <33C76A7A.15E4@swipnet.se> Date: Sat, 12 Jul 1997 13:28:58 +0200 From: Deltaman MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: My structures get broken when I fwrite Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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