下面的这个链表为什么老是不对呢,哪个大虾能帮帮我行吗
#include "stdio.h"
#include "malloc.h"
#define LEN sizeof(struct stud)
struct stud
{
int num;
float scores;
struct stud *next;
};
main()
{
struct stud *head,*p1,*p2;
int n=0;
p1=p2=(struct stud *)malloc(LEN);
scanf("num=%d,scores=%f",&p1->num,&p1->scores);
head=NULL;
while(p1->num!=0)
{
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct stud *)malloc(LEN);
scanf("num=%d,scores=%f",&p1->num,&p1->scores);
}
p2->next=NULL;
p2=head;
while(p2->next!=NULL)
{
printf("num=%d scores=%f",p2->num,p2->scores);
p2=p2->next;
}
getch();
}