clarification

Discussion in 'C' started by punith, Sep 19, 2007.

  1. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer
    Hi all

    Given the following structure
    Code:
    typedef struct value_pair {
            char                    name[40];
            int                      attribute;
            int                      type;
            int                     length; /* of strvalue */
            uint32_t              lvalue;
            LRAD_TOKEN     operator;
            uint8_t                 strvalue[MAX_STRING_LEN];
            ATTR_FLAGS      flags;
            struct value_pair   *next;
    } VALUE_PAIR;
    
    I am not understanding this small function
    Code:
    void pairadd(VALUE_PAIR **first, VALUE_PAIR *add)
    {
            VALUE_PAIR *i;
    
            if (*first == NULL) {
                    *first = add;
                    return;
            }
            for(i = *first; i->next; i = i->next)
                    ;
            i->next = add;
    }
    
    what for loop is doing???
    this function is called in the following sequence
    pairadd(&list, vp); where list and vp are again pointers of type VALUE_PAIR

    thanks in advance

    regards
    punith
     
    Last edited by a moderator: Sep 19, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    The for loop is moving through the linked list until it reaches the end, as indicated by the next pointer being null.

    Now, you've gotten your free help. Perhaps you could do a favor in return. USE CODE TAGS AROUND YOUR CODE. If you haven't read the "Before you post a query" thread, yet, please do that. Anything less is rude to your potential (free) helpers.
     
  3. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice