arrayscstructdeclarationmember-access

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;

Solution

  • 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.