1
typedef struct
{
    char Flight[10];                    
    int iRequested;                     
} Request;

typedef struct Node
{
    Request   request;                       
    struct Node *pNext;                     
} Node;

I've always been troubled with linked lists so as I'm writing this code Im having trouble accessing a a variable of a struct within a struct. I'm having errors compiling the way I try to go about this problem. How can I access a struct variable within a struct? using pointers preferably, thank you!

0

1 Answer 1

1

You can do something like this-

typedef struct
{
    char Flight[10];                    
    int iRequested;                     
} Request;

typedef struct Node
{
    Request   request;                       
    struct Node *pNext;                     
} Node;


int main()
{

    Node mynode;

  mynode.request.iRequested=1;

 printf("iRequested is %d",mynode.request.iRequested);


}

Result-

iRequested is 1

Sign up to request clarification or add additional context in comments.

1 Comment

OP tagged the question as C, not C++: please write your solution in the correct language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.