2010-01-17 07:05:48 UTC
typedef struct list {
char key[30];
int freq;
struct list *next;
} list ;
So each node contains an array of 30 chars called the 'key', an int called freq and a pointer to the next node in the list.
My program crashes when I try to manipulate the lists, I'm new to C so I'm probably missing something (I still don't entirely get pointers..).
Here's an example from the main function:
int main( int argn, char **input ){
FILE *file;
list *data = malloc(sizeof(list));
data->freq = 1;
int n;
char d[500];
char *c;
if(argn>0){
file = fopen(input[1], "r");
n = fread(d,1,500,file);
c = d;
c[n]='\0';
c = lowercase(c);
c = purify(c);
data = readintolist(data,c);
fclose(file);
printf("%s\n", data->key );
} else {
printf("Error: No file found\n");
}
return 0;
}
Now before it even gets to the if statement, the program crashes as soon as it reaches the "data->freq = 1;" bit.
To make passing it around functions easier, I defined the data list as a pointer to the list, so I know that using "data.freq = 1;" won't work, I just don't know whats wrong! aha
Thanks in advance if you can help.