输出结果有问题,帮忙看看
#include "stdio.h"#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{char num[6];
char name[8];
char sex[2];
int age;
struct student *next;
}stu[10];
main()
{struct student *p,*pt,*head;
int i,length,iage;
int find=0; /*若找到待删除元素,则find=1,否则find=0*/
printf("Input length of list(<10):");
scanf("%d",&length);
/*建立链表*/
for(i=0;i<length;i++)
{p=(struct student *)malloc(LEN);
if(i==0)
head=pt=p;
else
pt->next=p;
pt=p;
printf("NO:");
scanf("%s",p->num);
printf("name:");
scanf("%s",p->name);
printf("sex:");
scanf("%s",p->sex);
printf("age:");
scanf("%d",&p->age);
}
p->next=NULL;
p=head;
printf("\nNO. name sex age\n"); /*显示*/
while(p!=NULL)
{printf("%4s%8s%6s%6d\n",p->num,p->name,p->sex,p->age);
p=p->next;
}
/*删除*/
printf("Input age:"); /*输入待删年龄*/
scanf("%d",&iage);
pt=head;
p=pt;
if(pt->age==iage) /*链头是待删元素*/
{p=pt->next;
head=pt=p;
find=1;
}
else /*链头不是待删元素*/
pt=pt->next;
while(pt!=NULL)
{if(pt->age==iage)
{p->next=pt->next;
find=1;
}
else
p=pt;
pt=pt->next;
}
if(!find)
printf("Not found%d.",iage);
p=head;
printf("\nNO. name sex age\n"); /*显示结果*/
while(p!=NULL)
{printf("%4s%8s%6s%6d\n",p->num,p->name,p->sex,p->age);
p=p->next;
}
getch();
}