为何可以编译通过,但在我用scanf 输入 float型变量就报如下错误???
可是这是谭浩强C语言教程, page 279的例程啊?? 见鬼了…….
我的环境为:Turob C 2.0
please input an Integer Number for No. : 3
please input a Float number for score : scanf : floating point formats not link
ed
Abnormal program termination
——————code———————————————————————
#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int num;
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);
printf(“please input an Integer Number for No. : “);
scanf(“%d”,&p1->num);
printf(“please input a Float number for score : “);
scanf(“%f”,&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);
printf(“please input an Integer Number for No. again: “);
scanf(“%d”,&p1->num);
/*
printf(“please input a Float number for score again: “);
scanf(“%f”,&p1->score);*/
}
p2->next = NULL;
return (head);
}
/*
struct student *del(struct student,int)
{
}
*/
void print(struct student *head)
{
struct student *p;
printf(“\nNow,These %d Records are : \n”,n);
p = head;
if(head!=NULL)
do
{
/*printf(“%d,%f\n”,p->num,p->score);*/
printf(“%d \n”,p->num);
p = p->next;
}while(p!=NULL);
}
int main()
{
struct student *h;
h = creat();
print(h);
return 0;
}
——————code———————————————————————
我实在灭有明白这是怎么回事,感谢了!
>> 本文固定链接: http://www.vcgood.com/archives/1620
对,我以前也遇到过这个问题,一直无法理解为什么有时用FLOAT就大错的
在群里问也没人答得上来,但也友人遇到过这个错误…………
请高手指点
系统有问题
Unable to open include file ‘MALLOC.H’
Unknown preprocessor directive: ‘defide’
Undefined symbol ‘LEN’ in function creat
Undefined symbol ‘num’ in function creat
Non-portable pointer comparison in function creat
Undefined symbol ‘score’ in function creat
Non-portable pointer comparison in function creat
urbo C(TC)系统的浮点连接错误
用TC-2.0系统编写小的C程序,如果程序里用到浮点输入,有时运行中会出现下面错误信息:
scanf : floating point formats not linked
Abnormal program termination
这个错误信息的意思是:scanf的浮点格式转换程序没有连接。
TC开发时(80年代)DOS下的存储资源紧缺,因此TC在编译时尽量不加入无关部分。在没发现需要做浮点转换时,就不将这个部分安装到可执行程序里。但有时TC不能正确识别实际确实需要浮点转换,因此就会出现上面错误。
解决方法:设法告诉TC需要做浮点数输入转换。下面例子里增加了一个double变量并用它输入。
大程序里由于变量很多,只要有了线索,TC就会把浮点转换连上,因此反而不常遇到这个问题。
#include<stdio.h>
#define PR printf
#define N 3
struct staff
{
char name[10];
double swage;
double allowance;
double insurance;
}staf[N];
short i=0;
double x,y,z;
void get(void)
{
for(i=0;i<N;i++)
{
PR(“输入职工%d的信息\n”,i+1);
PR(“请输入职工姓名: “);
scanf(“%s”,staf[i].name);
PR(“请输入基本工资: “);
scanf(“%lf”,&x);
staf[i].swage=x;
PR(“请输入补贴: “);
scanf(“%lf”,&y);
staf[i].allowance=y;
PR(“请输入保险: “);
scanf(“%lf”,&z);
staf[i].insurance=z;
}
}
void main()
{
get();
}