ok, im quite a bit furthur with this project but I have another problem *surprise*.
I have got my program to read the list in now, but I am trying to search it and it seems to start the list at the last word entered and then tries to access the one after it rather than the word entered before it.
I have included the code I have used below although there is quite a lot.
I get a segmentation fault in the searchlist function when trying to access the next item of the list. I think this is a fairly stupid mistake so hopefully something will jump out.
Thanks
Code:
char searchlist(list *root, char *word, int a, int b){
if (root->thisnode[0] == '&'){
return a;
}
else if(strcmp(word, root->thisnode) == 0){
a++;
b++;
searchlist(root->next, word, a, b);
}
else{
a++;
searchlist(root->next, word, a, b);
}
return 0;
}
list *insertlinkedlist(char *x){
list *a;
char y[50];
int b;
int c;
int e;
b = 0;
e = 0;
while (x[b] != '\0'){
c = 0;
while (x[b] != ' '){
y[c] = x[b];
b++;
c++;
}
y[c] = '\0';
a = insertlist(y, a);
b++;
}
y[0] = '\0';
a = insertlist(y,a);
return a;
}
list *insertlist(char hd[50], list *a1){
list *a;
int b;
int c;
b = strlen(hd);
a = calloc(1,sizeof(list));
for (c = 0; c < b; c++){
a->thisnode[c] = hd[c];
}
a->next = a1;
return a;
free (a);
}
int main(){
char a[30];
char b[50];
char *y;
list *z;
int c;
scanf("%s", a);
y = readdata(a);
printf("%s", y);
z = insertlinkedlist(y);
printf("\nEnter word for retrieval:");
scanf("%s", b);
c = searchlist(z,b,0,0);
printf("%d", c);
free(y);
free(z);
return 0;
}