I have a problem working this one out for strings... this small function should return a pointer to fred for example if fred were in the list or NULL otherwise, a simple find operation. The output always returns the same pointer no matter how I've tried different things.
In short, is the logic of this method sound? Can anyone spot the problem? The correct header files are called and it compiles but just doesn't output the correct pointer ---> given a string n and a pointer to the list as parameters. The linked list has only 2 parts to the struct - data_item and next.
Code:
node_ptr find(char *n, node_ptr list)
{
node_ptr located = list->next;
while(located != NULL && (!strcmp(located->data_item, n) == 0));
{
located = located->next;
}
return located;
}