链表的问题?
我这个程序没错误怎么输入不了内容啊!请教各位大侠帮我看看啊 #include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int number;
char name[10];
char sex;
int age;
struct student *next;
};
int n;
struct student *creat()
{
struct student *p1,*p2,*head;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%d,%s,%c,%d",&p1->number,p1->name,&p1->sex,&p1->age);
head=NULL;
while(p1->age!=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->number,p1->name,&p1->sex,&p1->age);
}
p2->next=NULL;
return head;
}
struct student *del(struct student *head,int age)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("list null\n");
return head;
}
p1=head;
while(age!=p1->age && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(age==p1->age)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
}
else
printf("%d not been found:\n",age);
return head;
}
struct student *insert(struct student *head,struct student *stu)
{
struct student *p1,*p2,*p0;
p0=stu;
p1=head;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while(p1->number<p0->number && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p0->number==p1->number)
{
if(head==p1)
head=p0;
else
{
p2->next=p0;
p0->next=p1;
}
}
else
{
p1->next=p0;
p0->next=NULL;
}
n=n+1;
}
return head;
}
void print(struct student *head)
{
struct student *p,*q;
p=head;
while(p->next!=NULL)
{
printf("%d %s %c %d",p->number,p->name,p->sex,p->age);
q=p;
p=p->next;
}
}
void main()
{
struct student *head,*stu;
int age;
head=creat();
print(head);
scanf("%d",&age);
while(age!=0)
{
head=del(head,age);
print(head);
printf(" input the deleted age:\n");
scanf("%d",&age);
}
printf("input the insert nunber:\n");
stu=(struct student*)malloc(LEN);
scanf("%d,%s,%c,%d",&stu->number,stu->name,&stu->sex,&stu->age);
while(stu->age!=0)
{
head=insert(head,stu);
print(head);
stu=(struct student *)malloc(LEN);
scanf("%d,%s,%c,%d",&stu->number,stu->name,&stu->sex,&stu->age);
}
}