C语言中 运行出现 scanf:floatting point formats not linked Abnormal program termination

来源:百度知道 编辑:UC知道 时间:2024/06/14 09:56:52
这是怎么回事啊?把float换成int型的一切正常。只要输入实型变量就出现这个错误。程序如下:
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
char name[10];
char sex;
float 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 %s %c %f",&p1->num,p1->name,&p1->sex,&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 %s %c %f",&p1->num,p1->name,&p1->sex,&p1->score);
}
p2->next=NULL;
return(head);
}

void print(struct student * head)
{struct student *p;
printf("\nThe %f records at present are:\n",n);

你说的错误我没遇到,只是发现个别小问题。
print函数里
printf("\nThe %f records at present are:\n",n);
这里,n是int型的,应该用%d
printf("%ld %s %c %d\n",p->num,p->name,p->sex,p->score);
这里,score是float型,应该用%f。

楼上说得没错