大家帮我看看这个程序!
大家帮我看看这个程序!输入时候一直输下去了,没有反应(创建链表的时候)!
程序代码:#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[8];
float high;
long int weight;
struct student *next;
};
int n,i;
struct student *creat()//创建链表
{
i=1;
struct student *p,*head,*stud;
head=NULL;
stud=p=(struct student *)malloc(sizeof(struct student));
printf("请输入学生 %d 的身高体重姓名:",i);
scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
while(stud->high!=0)
{
n++;
if(n==1)
{
head=stud;
head->next=NULL;
}
else
p->next=stud;
p=stud;
stud=(struct student *)malloc(sizeof(struct student));
printf("请输入学生 %d 的姓名身高体重:",++i);
scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
}
p->next=NULL;
return(head);
}
struct student * search(struct student *head)//找出高度最高的那个学生
{
struct student *p,*q,*t;
float k;
t=p=head;
do
{
if(t->high<p->high)
{
k=t->high;
t->high=p->high;
p->high=k;
q=p;
}
p=p->next;
}while(p!=NULL);
return q;
}
struct student * find(struct student *head)//找出体重最重的那个学生
{
struct student *p,*q,*t;
int m;
t=p=head;
do
{
if(t->weight<p->weight)
{
m=t->weight;
t->weight=p->weight;
p->weight=m;
q=p;
}
p=p->next;
}while(p!=NULL);
return q;
}
void main(void)
{
struct student *p,*q,*head;
head=creat();
p=search(head);
printf("%s%f%ld",p->high,p->weight,p->name);
q=find(head);
printf("%s%f%ld",p->high,p->weight,p->name);
}



