因此,我尝试创建一个学生数据库,其结构以学生的姓名为主要内容,并包含性别、年龄等其他因素。另外,在该结构中,还有另一个包含学生类(class)成绩的结构:我该怎么做?
最佳答案
您在理解方面的基本问题是您的students
结构错误,并且它误导了您。查看此内容并尝试了解它是如何工作的、为什么它是您所需要的以及如何使用它来解决您的问题:
struct student{
char name[20];
int age;
char gender[7];
struct grades gr;
struct student *nextStudent;
};
你的打印函数,可能看起来像这样
void print (void){
for(struct student *stud = root; stud != NULL; stud = stud->nextStudent){
printf("Name: %s\n",stud->name);
printf("Grades: %s, %s, %s, %s\n", stud->gr.math, stud->gr.history, stud->gr.science, stud->gr.writing);
}
}
关于C编程: How to create a linked list using a struct within a struct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47598570/