Thread: Clean list function

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    43

    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()

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Code:
    if (strcmp(link1->fname, link2->fname) && !strcmp(link1->lname, link2->lname))
    Looks so much cleaner.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by master5001 View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM