From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot) Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro PackFile I/O Date: Sat, 08 Feb 1997 02:23:32 GMT Organization: Oxford University Lines: 61 Message-ID: <32fbdc68.56039181@news.ox.ac.uk> References: <01bc1556$2282cee0$95ddf4cc AT express DOT ca DOT express DOT ca> NNTP-Posting-Host: mc31.merton.ox.ac.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On 8 Feb 1997 00:23:09 GMT, "Chris" wrote: >typedef struct Map { > int w, h; > char name[8]; > BITMAP *tiles[60][60]; >} Map; Fine. What you wrote next was wrong, though... > Map *m; > pack_fwrite(m->name, 8, fl); I assume some code goes in between these two lines :) Otherwise, there is no map to save... Make sure there's a malloc in there somewhere [e.g. m=(Map *)malloc(sizeof(Map));] > pack_iputw(m->w, fl); fine (assuming the file is open) > pack_iputw(m->h, fl); fine > for(x=0; x< 60; x++) > for(y=0; y< 60; y++) > pack_fwrite(m->tiles[x][y], sizeof(BITMAP), fl); No. You're saving the wrong thing here... m->tiles[x][y] is a pointer to the bitmap. So you're writing this to the file followed by a massive chunk which is nearly as long as the BITMAP struct is. Sorry, but this is pointless. What you need to save is the image - this begins at the location pointed to by m->tiles[x][y]->line, and continues for width*height bytes, I think... Try using this line instead of the present pack_fwrite line: pack_fwrite(m->tiles[x][y]->line,width*height,fl); The loading routine then becomes: >And a loading routine which looks like this: > Map *m; m=(Map *)malloc(sizeof(Map)); > pack_fread(m->name, 8, fl); > m->w = pack_igetw(fl); > m->h = pack_igetw(fl); > for(x=0; x< 60; x++) > for(y=0; y< 60; y++) At this stage you need to allocate the bitmaps you're putting the information into, so we add a create_bitmap and correct the pack_fread as above: * { * m->tiles[x][y]=create_bitmap(width,height); * pack_fread(m->tiles[x][y]->line,width*height,fl); * } You should #include for the malloc command. Hope this helps, if not send me your source and I'd be happy to peruse it. George Foot