简体   繁体   中英

Does multiple struct (Nested structure) exist in C?

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;

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM