下面的链表程序中若是把score的输出输入格式改为float就会报错:浮点语法错误。改成int就可以,不知道原因是什么?
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
int score;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%d",&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,%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
main()
{struct student *head;
void print(struct student *);
printf("\nInput data:\n");
head=creat();
print(head);
getch();
}
void print(struct student *head)
{struct student *p;
printf("\nNow ,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{
printf("%ld %5d\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}