#define LEN sizeof(struct student)
#define NULL 0
main()
{struct student
{long num;
float score;
struct student *next;
};
int n;
struct student *p1,*p2,*head;
n=0;
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;
printf("n=%d\n",n);
do
{printf("%ld %5.2f\n",head->num,head->score);
head=head->next;
} while(head!=NULL);
getch();
}
这个程序能成功编译,但在执行scanf 语句时被终止,提示:scanf : floating point formats not linked, abnormal program termination
如果将程序中的float score 更改为 int score 其他地方做相应更改,则能达到预期的结果.
为什么?
[此贴子已经被作者于2006-12-16 22:20:59编辑过]