0

A project in C is being forced upon me. I do not have much C knowledge, but I'm assuming the answer is simple.

struct s1 {
  char *text;
  int num;
};

struct s2 {
  struct s1 vals[5];  
  int numbers;   
};

Assume s2 is already populated. How do access num from s1? I was assuming I would do something like

struct s2 temp;
//temp is populated somehow, doesn't matter in the case
printf("%d\n", temp.vals[0]->num);  

but that doesnt work. Any suggestions?

1
  • "This question was caused by a simple typographical error." VTC Commented Mar 16, 2014 at 22:43

1 Answer 1

5

Use temp.vals[0].num. The -> operator can only be used if you are using a pointer to a struct. You are using a struct directly.

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.