scanf : floating point formats not linked

来源:百度知道 编辑:UC知道 时间:2024/06/11 19:23:07
#include<stdio.h>
#define N 3
typedef struct student
{ long xuehao;
float score[2];
} student;
void main()
{
//int a[N],b[N];
int i=0;
student stu[N];
printf("input:");
for(i=0;i<N;i++)
{
//scanf("%d%d",&a[i],&b[i]);
scanf("%ld %f %f",&stu[i].xuehao,&stu[i].score[0],&stu[i].score[1]);
}
for(i=0;i<N;i++)
{
printf("%ld\t%f\t%f\t\n%",stu[i].xuehao,stu[i].score[0],stu[i].score[1]);
//printf("%d\t%d\n",a[i],b[i]);
}
//system("Pause");
}
在Borland C++ for dos下运行输入第一个数后出现题目的错误(scanf : floating point formats not linked;Abnormal program termination)
如何解决?

都不行啊!

你说的是不是TC++3?
你的代码我测试正常,觉得你用的可能不是个完全版的或者目录设置错误.建议下载一个Dos安装版的安装到固定目录,基本不用设置,然后RAR打包,这样运行环境比较稳定(固定),一旦有问题,删除那个目录再恢复压缩包就行了,Dos的东西设置起来太麻烦.

//下面是我帮你在原文上改正的;
#include<stdio.h>
#define N 3
struct student
{ long xuehao;
float score[2];
};
void main()
{
int i=0;
student stu[N];

printf("input:\n");
for(i=0;i<N;i++)
scanf("%ld %f %f",&stu[i].xuehao,&stu[i].score[0],&stu[i].score[1]);

for(i=0;i<N;i++)
printf("%ld\t%.2f\t%.2f\n%",stu[i].xuehao,stu[i].score[0],stu[i].score[1]);
}

没有错,你用的编译软件有问题

TC2.0的bug, 浮点库连接问题, 解决方法很简单, 在main开始的时候随便加个浮点运算的语句就可以了, 比如:

int main()
{
float xxx = 0.0f;

// 之后不边变
}

再给你个地址:
http://hi.baidu.com/eocodes/b