Mail Archives: djgpp/1998/03/21/15:46:24
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 -