请各位高手帮我看看这个程序
请各位高手帮我看看这个程序.建立一个链表,每个结点包括:学号,姓名,性别,年龄.输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则将此结点删去.
#include "stdio.h"
#include "conio.h"
#define len sizeof(struct student)
#define Null 0
struct student
{
int num;
char name[10];
char sex;
int age;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(len);
scanf("%d,%s,%c,%d",&p1->num,p1->name,&p1->sex,&p1->age);
head=Null;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(len);
scanf("%d,%s,%c,%d",&p1->num,p1->name,&p1->sex,&p1->age);
}
p2->next=Null;
return (head);
}
void print(struct student *head)
{
struct student *p;
p=head;
if(head!=Null)
do{
printf("%d,%s,%c,%d\n",p->num,p->name,p->sex,p->age);
p=p->next;
}while(p!=Null);
}
struct student *del(struct student *head,int Age)
{
struct student *p1,*p2;
p1=p2=head;
if(p1->next==Null)
if(p1->age==Age)head=Null;
else
printf("no find!");
else
while(p1->next!=Null)
{
if(p1->age==Age)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
p1=p2->next;
}
else
{p2=p1;p1=p1->next;}
}}
main()
{ int age;
struct student *head;
head=creat();
print(head);
printf("input a age:");
scanf("%d",&age);
head=del(head,age);
print(head);
getch();
}
不知道问题出在哪里?