//word frequency counter
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct words {
char word[255];
int count;
struct words *next;
} *pointer, *start, *previous;
int statistics();
int main(void)
{
statistics();
system("pause");
return 0;
}
int statistics()
{
FILE *fp;
int pom,a;
char quest[255];
start=NULL;
fp=fopen(name, "r");
fscanf(fp, "%s", &quest);
start = (struct words *)malloc(sizeof(struct words));
if(start==NULL)
return 0;
strcpy(start->word,quest);
++(start->count);
start->next = NULL;
previous = start;
while((a=fscanf(plik, "%s", &quest))!= EOF)
{
pom=0;
pointer = start;
do
{
previous = pointer->next;
if((strcasecmp(quest,pointer->word))==0)
{
++(pointer->count);
pom=1;
break;
}
pointer=pointer->next;
} while(previous!=NULL);
if(pom!=1)
{
pointer = (struct words *)malloc(sizeof(struct words));
if(pointer==NULL)
return 0;
strcpy(pointer->word, quest);
++(pointer->count);
previous->next = pointer;
pointer->next = NULL;
previous = pointer;
}
}
pointer = start;
do
{
previous = pointer->next;
printf("word %s X %d razy\n", pointer->word, pointer->count);
pointer = pointer->next;
} while (prevoius != NULL);
return 0;
}
i still keep on getting segfault here: prevoius->next=pointer; any attempt of helping would be appreciated.