Referencing pointer inside a structure pointer

This is a discussion on Referencing pointer inside a structure pointer within the C Programming forums, part of the General Programming Boards category; Hi I have a structure as follows Code: struct arptCd { char code[ARPCDLEN]; }; struct arptList { struct arptCd arpt; ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    50

    Referencing pointer inside a structure pointer

    Hi


    I have a structure as follows

    Code:
    struct arptCd
    {
        char code[ARPCDLEN];
    
    };
    
    struct arptList
    {
            struct arptCd arpt;
            struct arptCd *next;
    };
    
    struct halfTurnTime
    {
    
            struct arptList *arpt;
            float pctMgtArr;
            float pctMgtDep;
            float minmDep;
            float minmArr;
    
    };
    
    struct halfTurnTimeList{
            struct halfTurnTime halfTurnTimeData;
            struct halfTurnTime *next;
    };
    Here halfTurnTimeList is a linked list whose first element is pointer to arptList which is another linked list. I have allocated memory of halfTurnTimeList and pute it into variable name called node. I have created the linked list of arpt.But when i am trying to assign address of first note into the first element of halfTurnTimeList by following assignment

    node->arpt=firstArptNode

    Compiler showing error "struct halfTurnTimeListâ has no member named arpt".

    I made following task


    struct halfTurnTimeList *node=NULL
    node=calloca as halfTurnTimeList
    created linked list of Arpt node
    node->arpt=firstArptNode. firstArptNode is the address of the first node.


    How can i access a pointer member of structure pointer.

    Thanks in advance
    Sas

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,488
    node is of type halfTurnTimeList, which only has 2 elements, halfTurnTimeData and next. It's halfTurnTimeData that is of type halfTurnTime and has an element named aprt. Thus, you need node->halfTurnTimeData->arpt = firstArptNode.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    50
    Thanks a lot for pointing out the error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. union inside structure
    By vijay s in forum C Programming
    Replies: 1
    Last Post: 12-03-2009, 06:21 AM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  4. Can a pointer point to different data structure?
    By franziss in forum C Programming
    Replies: 9
    Last Post: 09-04-2005, 11:51 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21