A
A
Ander8132020-04-23 18:30:51
C++ / C#
Ander813, 2020-04-23 18:30:51

How to fill in a structure in SI?

struct student {
  char name[64];
  int marks[5];
};

struct Group {
  struct student* stud;
  int size;
  int id;
};

struct Faculty {
  struct Group* groups;
  int size;
  char faculty[100];
};

struct University {
  struct Faculty* faculties;
  int size;
  char univer[100];
};

int main() {
  struct University* unik = (struct University*)malloc(sizeof(struct University));
  unik->size = 3; 
  unik->faculties = (struct Faculty*)malloc(unik->size * sizeof(struct Faculty));
  unik->faculties->groups = (struct Group*)malloc(2 * sizeof(struct Group));
  unik->faculties->groups->elements = (struct student*)malloc(5 * sizeof(struct student));
  printf("University name ");
  scanf_s("%s", unik->univer, 99);
        ...
  return 0;
}


There is a university structure and it must be somehow filled in main so that there are 3 faculties, each faculty has 2 groups, each group has 5 people.
The question is how to fill it in so that it is not unwieldy. Tried with {}, but gives an error "only one level of curly braces is allowed"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question