[Legacy Content] This page contains very old information, which might not be valid anymore, they are only kept here for legacy purposes.
if you have any inquiries, feel free to contact me! Click here
Created: Thursday, 02 January 2014 Written by Ehab Eldeeb
This is the best definition for this .. "Nested Struct" which is actually a struct including a struct inside of it.
First of all, you should read this article: "What are structs?"
Now let's explain what a nested struct is
typedef struct {
char name[20];
float grade;
} course;
typedef struct {
char name[100];
int ID;
float GPA;
course subject[6];
} student;
int main() {
student mystudent[20];
.......
.......
.......
return 0;
}To deal with the course of the student you will do like that..
mystudent[i].subject[j].name;
mystudent[i].subject[j].grade;
inside two for loops of course .. one for the student (20) and one for the subject (6)Simply, Struct inside another. As easy as that :)