0

the title pretty much says it all i have a struct with an array of struct as one of its member and I can't figure out how to access

struct Member{
   short x;
...
};

struct List{
   struct Member members[MAX_MEMBER];
...
};
short function(const struct List*n){
 if((n->members[i])->x ...)
...
}

I tried somethin like that but it doesn't work. Thanks for your answer

1
  • You need .x instead of ->x. n->members[i] is a struct Member, so you don't need the pointer arrow notation. And the parentheses are unnecessary too. If you're perverse enough, you could use (&n->members[i])->x, but that is silly. Commented May 11, 2021 at 15:05

1 Answer 1

2

n->members is an array of struct Member, not an array of pointers. Hence n->members[i] is a struct Member, not a struct Member *. You should therefore access its members using . and not ->. Try:

if (n->members[i].x ...)
Sign up to request clarification or add additional context in comments.

Comments

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.