为什么可以建立一个班级一名学生或者多个班级,但是建立一个班级里头多名学生就运行卡死,求大佬解释,解决下问题,拜托拜托拜托
目的:
一个年级,相当链表A,
该年级5个班,每个班5个人,相当于链表B1--B5。
做一个学生成绩管理系统
//学生成绩
struct B{
int chinese;
int math;
int english;
int sum;
int StudentID;
struct B *next;
};
//班级
struct A{
int ClassroomID;
struct B *BHead;
struct A *next;
};
//学生成绩链表
struct B *B_studentlink(struct B *head,int number)
{
struct B *p = head;
struct B *new;
int i;
for(i=1 ; i<=number; i++)
{
new = (struct B*)malloc(sizeof(struct B));
new->StudentID = i;
if( p == NULL)
{
p = new;
head = p;
}
else{
while(p->next != NULL)
{
p = p->next;
}
p->next = new;
}
}
return head;
}
//班级链表
struct A *A_classlink(struct A *head,int classnumber,int classStudentNumber)
{
struct A *p = head;
struct B *student;
struct A *new;
int j;
for(j=1; j<=classStudentNumber; j++)
{
student = NULL;
new = (struct A*)malloc(sizeof(struct A));
new->ClassroomID = j;
student = B_studentlink(student,classStudentNumber);
new->BHead = student;
if(p ==NULL)
{
p = new;
head = p;
}
else{
while(p->next != NULL)
{
p = p->next;
}
p->next = new;
}
}
return head;
}
//输入数据
struct A *InputData(struct A *Classhead)
{
struct A *p = Classhead;
struct B *q = NULL;
Classhead = p;
while(p != NULL)
{
q = p->BHead;
p->BHead = q;
while(q != NULL)
{
printf("Please Scanf %d Ceng the %d student\n",p->ClassroomID,q->StudentID);
printf("The chinese is\n");
scanf("%d",&(q->chinese) );
printf("The math is\n");
scanf("%d",&(q->math) );
printf("The english is\n");
scanf("%d",&(q->english) );
putchar('\n');
q->sum = (q->chinese)+(q->math)+(q->english);
printf("#######################################\n");
q= q->next;
}
p = p->next;
}
return Classhead;
}
``
``
int main()
{
int B_number;
int A_number;
struct A *Classhead = NULL;
printf("Please scanf how much Ceng\n");
scanf("%d",&A_number);
printf("Please scanf how much student\n");
scanf("%d",&B_number);
putchar('\n');
Classhead = A_classlink(Classhead,A_number,B_number);//建立链表
Classhead = InputData(Classhead);//输入数据
return 0;
}