delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/14/12:18:47

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: General protection fault because of modulus?
Date: Wed, 09 Jul 1997 17:48:09 -0400
Organization: Cornell University http://www.cornell.edu
Lines: 63
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <33C40719.7522@cornell.edu>
References: <01bc8c6e$c991d480$3564a8c0 AT Kelly DOT ns1 DOT uswest DOT net>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0013.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019