帮忙修改一下,不知道哪里出错了
#include <stdio.h>#include <stdlib.h>
struct student
{
char name[9];
int cj;
student *next;
};
student *create(int n);
student *del_stu(student *h);
int main(void)
{
student *head,*p;
int n;
printf("请输入n:");
scanf("%d",&n);
head=create(n);
while(head=del_stu(head));
p=head;
while(p!=NULL)
{
printf("%s %d\n",p->name,p->cj);
p=p->next;
}
return 0;
}
student *create(int n)
{
student *h,*p1,*p2;
int i;
p1=h=(student *)malloc(sizeof(student));
scanf("%s%d",h->name,&h->cj);
for (i=2;i<=n;i++)
{
p2=(student *)malloc(sizeof(student));
scanf("%s%d",p2->name,&p2->cj);
p1->next=p2;
p1=p2;
}
p2->next=NULL;
return h;
}
student *del_stu(student *h)
{
student *p1=h,*p2;
if (h=NULL)
return h;
if (h->cj<60)
{
h=h->next;
delete p1;
p1=h;
}
else
while (p1->next!=NULL)
{
p2=p1->next;
if (p2->cj<60)
{
p1->next=p2->next;
delete p2;
break;
}
else
p1=p2;
}
return h;
}