Mail Archives: djgpp/1997/07/14/12:18:47
levity AT minn DOT net wrote:
>
> I am writing a program for the purpous of learing how to read binary
> files.
in general, it is not a good idea to read/write whole structures at
once.
> I am using the modulus fo counting coloms for the out put but every
> time I add the code to do this the program runs and then ends with a
> general protection fault.
i do not really understand what you mean by that. i saw in the code that
you are at least checking the compression flag. are you sure the bitmap
you are reading is not compressed (using RLE)?
> Also for future reference should I include my code in a
> different way when posting these questions?
it would help to see the contents of the file bmphead.h.
also, i guess it is a matter if taste, but i find a block of
(void) printf(....)
statements distracting, especially when trying to read what is happening
on screen.
now that i got started talking about style, i have one recommendation.
> FILE *fbmp = fopen( name, "rb");
> if (fbmp == 0)
> {
> printf("Could not open file %s\n", name);
> return 0;
> }
not being able to open the file is a failure. 0, however, is
traditionally used to indicate success. without being too pushy, i would
recommend changing the code above to:
FILE *fbmp = fopen( name, "rb");
if (fbmp == 0)
{
perror(name);
exit(EXIT_FAILURE);
}
after all, you already included stdlib.h and stdio.h.
anyway, i am talking too much. it would help to see how the structures
you use are defined.
--
Sinan
*******************************************************************
A. Sinan Unur WWWWWW
|--O+O
mailto:sinan DOT unur AT cornell DOT edu C ^
http://www.people.cornell.edu/pages/asu1/ \ ~/
Unsolicited e-mail is _not_ welcome, and will be billed for.
*******************************************************************
- Raw text -