程序有点问题,看不明白。
程序能运行,就是输入时,刚输一数字确定就结束程序的,提示也看不明白。
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};
int n;
/*以下代码创建链表*/
struct student *creat(void)
{struct student *head,*p1,*p2;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
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("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
/*此函数输出链表中的所有值*/
void print(struct student *head)
{struct student *p;
printf("\nTHESE %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%ld,%5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
/*下面为主函数*/
main()
{struct student *pp;
pp=creat();
print(pp);
}