0

I have the following structures, and I want be able to access elements of the StudentType:

typedef struct {
  int  studentID;
  char name[MAX_STR];
  char degree[MAX_STR];
} StudentType;

typedef struct {
  StudentType *elements[MAX_ARR];
  int size;
} StudentArrType;

My function:

void initStuArr(int studentID, char *name, char *degree, StudentType **stu, StudentArrType **stuArr){

I have tried the following both of which don't allow me to access *elements:

stuArr->*elements->studentID = studentID

and

stuArr->(*elements)->studentID = studentID

I am receiving the error: expected identifier before '*' token and '(' token when I try the 2 above. when I try stuArr->elements->studentID = student ID without using the *, I get the error: request for member 'elements' in something not a structure or union.

How can I access *elements?

1 Answer 1

1

Since stuArr is a pointer to a pointer, you need to dereference it with * to get to the pointer. And since elements is an array, you need to index it to get to a StudentType *, which you can then use to get to studentId.

(*stuArr)->elements[i]->studentId.
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.