我正在尝试创建一个学生链接列表,每个学生都有一个成绩链接列表,但是我无法访问学生链接列表中的成绩链接列表。
typedef struct student_data_struct{
char student[MAX];
struct grades_list_struct *gradeP;
} student_Data;
typedef struct student_list_struct{
student_Data studentData;
struct student_list_struct *next;
} StudentNode;
typedef struct grades_list_struct{
int grade;
struct grades_list_struct *next;
} GradeNode;
GradeNode *insertGrade(int grade, GradeNode *head){
GradeNode *newNode=NULL;
newNode=(GradeNode*)calloc(1, sizeof(GradeNode));
if(head!=NULL){
newNode->grade=grade;
newNode->next=head;
return newNode;
} else {
newNode->grade=grade;
newNode->next=NULL;
return newNode;
}
}
StudentNode *insertStudent(char studentName[MAX], int studentGrade, StudentNode *head){
StudentNode *newNode=NULL;
newNode=(StudentNode*)calloc(1, sizeof(StudentNode));
newNode->studentData->gradeP=(GradeNode*)calloc(1, sizeof(GradeNode));
if (head==NULL){
strcpy(newNode->studentData.student, studentName);
newNode->next=NULL;
newNode->studentData->gradeP=insertGrade(studentGrade, newNode->studentData->gradeP);
return newNode;
} else {
strcpy(newNode->student, studentName);
newNode->gradeP->grade=studentGrade;
newNode->studentData->gradeP=insertGrade(studentGrade, newNode->studentData->gradeP);
return newNode;
}
}
当我尝试为等级指针分配内存时,
newNode->studentData->gradeP=(GradeNode*)calloc(1, sizeof(GradeNode));
我得到错误:
error: invalid type argument of '->' (have 'student_Data' {aka 'struct student_data_struct'})
同样,当我尝试为学生插入成绩时,
newNode->studentData->gradeP=insertGrade(studentGrade, newNode->studentData->gradeP);
我得到错误:
error: invalid type argument of '->' (have 'student_Data' {aka 'struct student_data_struct'})
任何帮助将不胜感激。