1

I wonder if there is a way to declare multiple structs in C. For example, I made this:

struct Team{
    char TeamName[20];
    int Point;
    int Goals;
};
typedef struct TeamCup {
    char GroupID;
    struct Team team;
}Group;
Group g1, g2;

I want each TeamCup to have 4 teams. But when it comes to input process, in my loop, the variable here is undefined:

g1.Team[i].Point;
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
NewbieBoy
  • 73
  • 4
  • 3
    If you want each `TeamCup` to have `4` `Team`, then you just have to write `struct Team team[4];` as always if you want an array. Then you only have a typo left: `g1.Team[i].Point;` -> `g1.team[i].Point;` – user17732522 Jan 16 '22 at 09:56

1 Answers1

3

I want each TeamCup to have 4 teams

In this case you need to write

typedef struct TeamCup {
    char GroupID;
    struct Team team[4];
}Group;

and

g1.team[i].Point;

Thar is you need to declare an array of objects of the type struct Team within the structure struct TeamCup.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335