I'm working on a function that finds entries in an address book given the linked list (first), the fieldId (i.e. a number form 1-7, such that 1 = First..name, 2 = Last..name, 3 = Street..address, 4 = City, 5 = State, 6 = Zip..code, 7 = Phone..number), and the searchKey string array that the user intends to find in the list.
so my code looks something like this:
Code:
void find(struct Entry* first, int fieldId, char searchKey[101])
{
switch (fieldId)
{
case 1: {
while ( first != NULL ) {
if ( first->firstName == searchKey )
print_this_horseradish (first);
first = first->next;
}
break;
}
case 2: {
// similar
}
case 3: {
// similar
}
case 4: {
// similar
}
case 5: {
// similar
}
case 6: {
// similar
}
case 7: {
// similar
}
default: printf ("This cannot happen.");
}
so, in that comparison something's not right. I get just the very first entry on the linked list printed out when the condition ( first->firstName == searchKey ) is satisfied, and only once.
print_this_horseradish looks like this:
Code:
void print_this_horseradish (struct Entry* first)
{
printf ("%s, %s\n", first->lastName, first->firstName);
printf ("%s\n", first->streetAddress);
printf ("%s, %s %s\n", first->city, first->state, first->zipCode);
printf ("%s\n", first->phoneNumber);
printf ("\n");
}