这是一个关于学生成绩链表的题,明明可以正常运行PTA却报错
这是PTA报错情况和我的测试,最下面是我的代码
#include <stdio.h>
#include <stdlib.h>
struct stud_node {
int num;
char name[20];
int score;
struct stud_node *next;
};
struct stud_node *createlist();
struct stud_node *deletelist( struct stud_node *head, int min_score );
int main()
{
int min_score;
struct stud_node *p, *head = NULL;
head = createlist();
scanf("%d", &min_score);
head = deletelist(head, min_score);
for ( p = head; p != NULL; p = p->next )
printf("%d %s %d\n", p->num, p->name, p->score);
return 0;
}
struct stud_node *createlist()
{struct stud_node *tail,*e,tou;
tail=&tou;
tou.next=NULL;
e=&tou;
while((*e).num!=0)
{
e=(struct stud_node *)malloc(sizeof(struct stud_node));
e->next=NULL;
if(scanf("%d", &e->num) != EOF && e->num != 0)
{scanf("%s %d", e->name, &e->score);
tail->next=e;
tail=e;}
else
{tail->next=NULL;}
}
return tou.next;
}
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
struct stud_node *pre,tou2,*x;
tou2.next=head;
pre=&tou2;
x=head;
while(x!=NULL)
{
if(x->score<min_score)
{pre->next=x->next;
free(x);
x=pre->next;
}
else
{x=x->next;
pre=pre->next;
}
}
return tou2.next;
}