The snippets below are from my program that gets words, then prints them with the number of occurences.
It works almost fine except for it "forgots" that particular entry has been saved before and does NOT increment counter associated with it.
typedef struct {
char *word;
int occ;
}
words;
words *data=NULL;
int main(int argc, char **argv)
{
char *word;
words *temp;
int c,i,num;
words *ptr = NULL;
num=0;
while(1)
{
c=fgetc(infile);
if(c==EOF) break;
if(!isalpha(c)) continue;
else ungetc(c,infile);
word=getword(infile);
if(findword(word))
{
if(!(temp=realloc(data,sizeof(words)*(num+1))))
{ /* error handling */ }
else
data=temp;
}
else
free(word);
}
/* sort procedure here, irrelevant for the purpose of topic */
for(i=0;i<num;i++)
{
/*printf*/
}
return 0;
}
What's wrong with that code?
Thanks in advance!