简单的动态链表建立与输出问题,结果不对。
#include<stdio.h>#include<malloc.h>
#define NULL 0
#define KP (struct student*)malloc(sizeof(struct student))
#define SR scanf("%d%f",&p1->num,&p1->score)
#define SC printf("%d%f",p->num,p->score)
struct student
{
int num;
float score;
struct student *next;
};
struct student *creat()
{
struct student *head,*p1,*p2;
p2=p1=KP;
head=p1;
while((p1->num)!=0)
{
p1=KP;
SR;
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
p=head;
while(p->next!=NULL)
{
SC;
p=p->next;
}
}
int main()
{
//建立动态列表
struct student *head;
head=creat();
print(head);
return(0);
}