-
Clean list function
okay..so basically what i have is two linked lists(link1, link2) and link2 contains all of the values stored in link1. What i need to do is use string compare to clean the big list free of everything that is in link1. I believe i am on the right track but i am stuck as to how i should make this work. here is the code for the clean list function:
Code:
struct info_node * clean_list(struct info_node * link1, struct info_node * link2)
{
struct info_node * top = NULL ;
struct info_node * pre_pntr = NULL;
struct info_node* current_pntr = NULL;
While (current_pntr != NULL)
{
if (strcmp(link1->fname, link2->fname) && (strcmp(link1->lname, link2->lname) != 0)
{
link1 = link1->next ;
link2 = link2->next ;
}
else
{
}
}
return(0) ;
} //end of func clean_list()
-
You might want:
if ((strcmp(link1->fname, link2->fname)!=0) && (strcmp(link1->lname, link2->lname != 0)))
instead of
if (strcmp(link1->fname, link2->fname) && (strcmp(link1->lname, link2->lname) != 0)
because even if you correct the missing/extra parantheses, you will still only be testing the second strcmp.
-
Code:
if (strcmp(link1->fname, link2->fname) && !strcmp(link1->lname, link2->lname))
Looks so much cleaner.
-
Quote:
Originally Posted by
master5001
Code:
if (strcmp(link1->fname, link2->fname) && !strcmp(link1->lname, link2->lname))
Looks so much cleaner.
But that will be true when link1->fname is NOT equal to link2->fname and at the same time link1->lname IS equal to link2->lname.
You probably want to have a condition that is true when both are equal?
--
Mats
-
Until these OP's start throwing down cash or something, I will not be guaranteed to follow all of the logic embedded in sample code. This post included.