Problem with Linked list ()

Discussion in 'C' started by caraie, Aug 31, 2010.

  1. caraie

    caraie New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    i'm new in c, I have a problem with a Linked list maybe you can help me :)
    I made a linked list, and it's working fine, but i have a problem trying to access to an item using an index
    This is my structure and functions (i'll put a red note where i think the error is):
    Code:
    typedef struct node{
            int a;
            int b;
            struct nodo *next;
    }List;
    
    //insert function:
    List *insert(List **lst,    int a,     int b){
            assert(lst!=NULL);
            List *node=malloc(sizeof(List));
            node->next=*lst;
            *lst=node;
            node->a=a;
            node->b=b;
            return *lst;
    }
    [COLOR=Red]
    [B]List **get(List **lst, int index){
            int i=0;
            while ( (*lst != NULL) && (i< index) ){
                    lst=&(*lst)->next;
                    i++;
            }
            if (i==index){
                 return lst;
            }else{
                 return NULL;
            }
    }[/B][/COLOR]
    
    
    //im calling the get from other function using this:
    int valuea=get(&alist,10)->a;
    the error i'm receiving is:
    error: request for member 'a' in something not a structure or union

    I'll appreciate your help!
    Thank you!
     

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