www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/23/01:51:40

Message-ID: <3516069A.40AF@post.comstar.ru>
Date: Mon, 23 Mar 1998 09:52:10 +0300
From: Dim Zegebart <zager AT post DOT comstar DOT ru>
Reply-To: zager AT post DOT comstar DOT ru
Organization: Comstar Ltd.
MIME-Version: 1.0
To: zappaz AT xtra DOT co DOT nz
CC: DJGPP Mail List <djgpp AT delorie DOT com>
Subject: Re: Why why why??? (help me with this code....)
References: <6f0c4b$a9p$1 AT wolfman DOT xtra DOT co DOT nz>

zappaz AT xtra DOT co DOT nz wrote:
> 
> 
> long *frequencyTable(char *namein) {
>       FILE *infile;
>       int c;
>       long *freq; !!!!!!!!!

Thery simple ;) You just not allocate memory for freq table.
Look,
        freq=(long*)calloc(255); // calloc allocates and sets memory to
zero value
        if (!freq) 
         { printf("Error : not enough memory! \n);
           return(NULL);
         }
>       infile = fopen(namein,"r");
        if (infile) printf("Opening %s successful.\n", namein);
//        for (int i=0;i<256;i++) freq[i]=0; // not needed since we call
calloc.
>       while((c=getc(infile))!=EOF)
>          {
>             printf("got \"%c\"\n",c);  // not really neccesary
> >>>      freq[c]++;
>          }
>      fclose(infile);
>      return freq;
> }
> 

-- 
____ ____ 
|   \   /   Dim Zegebart
____/____   

Moscow Russia
WWW - http://www.geocities.com/siliconvalley/pines/7817
DZcomm - comm library for Allegro
Palantir - multitasking kernel for Allegro (based on PDMLWP)

- Raw text -


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