c-学生和课程链接列表的问题



我创建了一个课程链接列表,我试图编写一个函数来创建或更新学生链接列表,但在这个函数中,我引用了我的课程列表,它被称为"课程列表";。但是我得到了这样的错误:";不允许指向不完整类类型的指针";在用"***&";。有人能告诉我我的功能出了什么问题吗?

struct Grade
{
char courseNumber[6];
char grade[4];
struct Grade* next;
};

struct Student
{
char studentName[20];
struct Grade* studentGrades;
struct student* next;
};

struct Course
{
char courseNumber[6];
char courseName[31];
struct Course* next;
};

struct Student* updateStudentsList(char studentDetails[], struct Student* studentsList)
{
int i = 0, j = 0, r = 0, k = 0, p = 0, c = 0, g = 0, bool = 1, isStudentExist = 1;
char* studentName = " ";
char* courseNumHolder = " ";
char* gradeHolder = " ";
struct Student* head = studentsList;
if (studentsList == NULL)
{
studentsList = (struct Student*)malloc(sizeof(struct Student));
if (studentsList == NULL)
return studentsList;
while (studentDetails[i] != ':')
{
studentsList->studentName[i] = studentDetails[i];
i++;
}
studentsList->studentName[i] = '';
studentsList->next = NULL;
struct Grade* gradeHead = studentsList->studentGrades;
while (studentDetails[i] != 'n')
{
if (studentDetails[i] == ':' || studentDetails[i] == ';')
{
studentsList->studentGrades = (struct Grade*)malloc(sizeof(struct Grade));
if (studentsList->studentGrades == NULL)
return studentsList;
i++;
}
while (studentDetails[i] != ',')
{
studentsList->studentGrades->courseNumber[j] = studentDetails[i];
i++;
j++;
}
studentsList->studentGrades->courseNumber[j] = '';
while (studentDetails[i] != ';')
{
studentsList->studentGrades->grade[r] = studentDetails[i];
i++;
r++;
}
studentsList->studentGrades->grade[r] = '';
studentsList->studentGrades = studentsList->studentGrades->next;
}
studentsList->studentGrades = gradeHead;
return studentsList;
}
else
{
while (studentDetails[i] != ':')
{
studentName[p] = (char)malloc(sizeof(char));
studentName[p] = studentDetails[i];
i++;
p++;
}
studentName[p] = (char)malloc(sizeof(char));
studentName[p] = '';
while (studentDetails[i] != 'n')
{
while (studentDetails[i] != ',')
{
courseNumHolder[c] = (char)malloc(sizeof(char));
courseNumHolder[c] = studentDetails[i];
c++;
i++;
}
while (studentDetails[i] != ';')
{
gradeHolder[g] = (char)malloc(sizeof(char));
gradeHolder[g] - studentDetails[i];
g++;
i++;
}
while (studentsList->next != NULL)
{
if (strcmp(studentName, studentsList->studentName) == 0)
{
isStudentExist = 0;
while (studentsList->studentGrades != NULL)
{
if (strcmp(courseNumHolder, studentsList->studentGrades->courseNumber) == 0)
{
strcpy(studentsList->studentGrades->grade, gradeHolder);
bool = 0;
}
else if (studentsList->studentGrades->next == NULL && bool == 1)
{
studentsList->studentGrades->next = (struct Grade*)malloc(sizeof(struct Grade));
if (studentsList->studentGrades->next == NULL)
return studentsList;
strcpy(studentsList->studentGrades->next->courseNumber, courseNumHolder);
strcpy(studentsList->studentGrades->next->grade, gradeHolder);
}
studentsList->studentGrades = studentsList->studentGrades->next;
}
}
else if (studentsList->next == NULL && isStudentExist == 1)
{
studentsList->next = (struct Student*)malloc(sizeof(struct Student));
if (***studentsList->***next == NULL)
return studentsList;
strcpy(***studentsList***->next->studentName, studentName);
studentsList->next->studentGrades = (struct Grade*)malloc(sizeof(struct Grade));
if (***studentsList-***>next->studentGrades == NULL)
return studentsList;
strcpy***(studentsList->***next->studentGrades->courseNumber, courseNumHolder);
strcpy(***studentsList-***>next->studentGrades->grade, gradeHolder);
}
studentsList = studentsList->next;
}
studentsList = head;
}
}
}

Student结构定义中,下一个字段指向student而不是Student,因此它指向一个未定义的结构。

相关内容

  • 没有找到相关文章

最新更新