-
Searching a Linked-List
hi , i need help !!!!!!!
if i have a linked list structure
typedef struct person{
char name[MAX];
char address[MAX];
struct person *next;
} List;
typedef List *ManuPtr;
how can i search this linked list to print out all person with the same name ????
-
Hyaline,
It would help if you posted the code you have. Or, if you don't have any code, then pseudocode/logic.
I'll try to answer your question as is, but (as a disclaimer) I'm horribly tired and my mind is not working right.
The way I would go about this is to have a function that will:
Step through the entire list, from the first pointer until you hit the NULL termination.
-->For each node in the list, compare the target's name with the input value. I would use strcmp(). You probably haven't studied string functions yet, but strcmp is in your book and it's very easy to understand.
Again, it would help to post code. From what I see, I can't even be sure you have a properly built list.
-
Code:
while ( list != NULL ) {
if ( strcmp( list->name, "fred" ) == 0 ) {
printf( "yo!!\n" );
}
list = list->next;
}