cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/21/15:46:24

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why why why??? (help me with this code....)
Date: Sat, 21 Mar 1998 14:27:14 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 52
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <35141492.1C1837FF@cornell.edu>
References: <6f0c4b$a9p$1 AT wolfman DOT xtra DOT co DOT nz>
NNTP-Posting-Host: cu-dialup-1027.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

zappaz AT xtra DOT co DOT nz wrote:
> 
> I'm using DJGPP on Win95 platform and this little procedure is giving
> me a real headache. All it does is return a frequency table (array of
> longs) of how often each byte appears in the file "namein". If I
> include the line marked with ' > ' then the following while loop never
> gets executed. ? Also, if I include the line marked with ' >>> ' the
> program crashes, even if the ' > ' line _is_ included. ? ? Compiles
> OK.

freq is not initialized.

> long *frequencyTable(char *namein) {

IMHO, the following would be better design:

void frequency_table(FILE *f, long *t)
{
  /* assumes table points to an array of 256 longs
     initialized with zeros. */
  /* code to build table */

 return;
}

and then,

  FILE *input;
  long *table;

  ...

  input = fopen("filename.ext", "rb");
  table = calloc(256, sizeof(long));
  frequency_table(input, table);

> Also, I've often noticed that adding a printf statement in a loop
> makes a big difference to how that loop runs (usually the difference
> between running or not running at all). 

that usually means you made similar memory allocation mistake. adding
the printf changes the layout of the code in memory (in this case
changes what specific garbage table gets when the function is called.)

> Is this just something strange with DJGPP or is there something I 
> don't  know?

this and other basic C questions are better suited for
comp.lang.c.moderated or comp.lang.c (after reading the C faq, of
course.)

   -- Sinan

- Raw text -


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