一个C语言问题~~请教高手

fllwt 2008-05-08 09:41:37
#include "stdio.h"
void main()
{ float b[10][10];
scanf("%f",&b[0][0]);
printf("%f",b[0][0]);
}
这个程序能编译并且运行成功
#include "stdio.h"
void main()
{ float b[10][10];
scanf("%f",&b[0][0]);
//printf("%f",b[0][0]);
}
为什么 这个就不行了呢????
还有
#include "stdio.h"
void main()
{ float b[10][10];
scanf("%f",&b[0][0]);
b[0][0]=100;
}
这个也行,但是去掉后边一句就不行了 ( 自己分数不多,狠心发50了)
...全文
392 31 打赏 收藏 转发到动态 举报
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuciitc 2008-05-09
  • 打赏
  • 举报
回复
代码资料挺全,推荐一下:http://www.ciitc.com
minimana 2008-05-09
  • 打赏
  • 举报
回复
原来是这样.当年学C时,我的老师只是说我的机器问题.那家伙正败类!
skyell 2008-05-09
  • 打赏
  • 举报
回复
学到一个很好的经验,呵呵
chary8088 2008-05-09
  • 打赏
  • 举报
回复
无聊的问题
GCC运行正常
kingstarer 2008-05-08
  • 打赏
  • 举报
回复
这是TC的一个小bug,不能直接用scanf输出float二维数组元素

解决方法是先定义一个float temp;用scanf给temp赋值,然后用赋值语句将temp的值赋给二维数组元素
星羽 2008-05-08
  • 打赏
  • 举报
回复

msdn上的说法

Visual C++ Concepts: Building a C/C++ Program
C Run-Time Error R6002

Error Message
floating-point support not loaded

The necessary floating-point library was not linked.
To fix by checking the following possible causes

1.

The program was compiled or linked with an option, such as /FPi87, that requires a coprocessor, but the program was run on a machine that did not have a coprocessor installed.
2.

A format string for a printf_s or scanf_s function contained a floating-point format specification and the program did not contain any floating-point values or variables.
3.

The compiler minimizes a program's size by loading floating-point support only when necessary. The compiler cannot detect floating-point format specifications in format strings, so it does not load the necessary floating-point routines.
4.

Use a floating-point argument to correspond to the floating-point format specification, or perform a floating-point assignment elsewhere in the program. This causes floating-point support to be loaded.
5.

In a mixed-language program, a C library was specified before a FORTRAN library when the program was linked. Relink and specify the C library last.


fllwt 2008-05-08
  • 打赏
  • 举报
回复
哦了 Chiyer说得对 呵呵 编译器的 问题 唉。。。以后还是尽量学LINUX吧^_^
星羽 2008-05-08
  • 打赏
  • 举报
回复
fllwt 2008-05-08
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 fengdream 的回复:]
我运行起来没有任何错误

C:\Documents and Settings\IBM_T23>vim main.c

gcc main.c
main.c: In function `main':
main.c:4: warning: return type of 'main' is not `int'

./a.out
1.2
1.200000



[/Quote]
那就是我用的编译器的问题了 ^_^ 谢谢
fllwt 2008-05-08
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 Chiyer 的回复:]
http://support.microsoft.com/kb/q37507/
[/Quote]
可是为什么
#include <stdio.h>
int main()
{ float b[10][10];

scanf("%f",&b[0][0]);
printf("%f",b[0][0]);
}
这样也是对的呢?
难道 它在调试时也先进行了浮点运算
fengdream 2008-05-08
  • 打赏
  • 举报
回复
我运行起来没有任何错误

C:\Documents and Settings\IBM_T23>vim main.c

gcc main.c
main.c: In function `main':
main.c:4: warning: return type of 'main' is not `int'

./a.out
1.2
1.200000










星羽 2008-05-08
  • 打赏
  • 举报
回复
fllwt 2008-05-08
  • 打赏
  • 举报
回复
原来是这样 呵呵,被他困扰了有一个多小时了 谢谢各位了 结分去了!^_^
星羽 2008-05-08
  • 打赏
  • 举报
回复
我上面说的不一定全对,我记不清楚了,给你找了下ms的说法:

PRB: "Floating-point Support Not Loaded" Error with scanf()
View products that this article applies to.
Article ID : 37507
Last Review : September 17, 2003
Revision : 3.0
This article was previously published under Q37507
On This Page
SYMPTOMS
CAUSE
RESOLUTION
STATUS
MORE INFORMATION
Sample Code
SYMPTOMS
When an application uses the scanf() function to read a floating-point value from the console into an uninitialized "float" type global variable, an R6002 "floating-point format support not loaded" error occurs. This error also occurs when any formatted input routine is used to read a value.

Back to the top
CAUSE
The compiler does not generate a reference to the __fltused variable that instructs the linker to load the floating-point support module.

Back to the top
RESOLUTION
To work around this problem, initialize the floating-point variable or use the variable in an expression in the routine that contains the scanf() call.

Back to the top
STATUS
This behavior is expected. To minimize the size of the executable file, the compiler loads floating-point support only when it is required.

Back to the top
MORE INFORMATION
When a module uses only one of the formatted input routines and does not also initialize a floating-point variable, the compiler does not load floating-point support.

Remove the comment indication from either or both of the two lines in the sample code below to eliminate the R6002 error.

Back to the top
Sample Code

/*
* Compile options needed: none
*/

#include <stdio.h>
float x ;

main()
{
// Remove the comment from the next line to eliminate the error.
// x = 2.3 ;

scanf ("%f", &x) ;

// Remove the comment from the next line to eliminate the error.
// printf ("%f\n", x) ;
}


Back to the top
APPLIES TO
• The C Run-Time (CRT), when used with:
Microsoft C Professional Development System 6.0
Microsoft C Professional Development System 6.0a
Microsoft C Professional Development System 6.0a
Microsoft C Professional Development System 6.0
Microsoft C Professional Development System 6.0a
Microsoft C/C++ Professional Development System 7.0
Microsoft Visual C++ 1.0 Professional Edition
Microsoft Visual C++ 1.5 Professional Edition
Microsoft Visual C++ 5.0 Learning Edition
Microsoft Visual C++ 2.0 Professional Edition
Microsoft Visual C++ 4.0 Professional Edition
Microsoft Visual C++ 5.0 Professional Edition
Microsoft Visual C++ 6.0 Professional Edition
星羽 2008-05-08
  • 打赏
  • 举报
回复



这个现象叫
Floating-point Support Not Loaded

vc6.0 和更老的版本会存在这个问题,vs2005 如果你使用c编译也可能存在这个问题,使用c++编译一般就正常
这个现象的表现是,如果你在使用scanf函数之前没使用过浮点运算,那么scanf就会出错

比如

#include <stdio.h>


int main()
{
float x ;
scanf ("%f", &x) ;
return 0;

}



所以为了避免这个问题,你可以在scanf之前使用一下浮点运算

比如上面的改成

#include <stdio.h>


int main()
{
float x = 0.f;
scanf ("%f", &x) ;
return 0;

}

就没问题了
fllwt 2008-05-08
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 NKLoveRene 的回复:]
我刚才特意用dev c++试了
[/Quote]
刚才问了下别人,有出现这种情况的 而且我还换了台机子试试,还那样 我用的VC++ 我就郁闷了~!
gaosen_bit 2008-05-08
  • 打赏
  • 举报
回复

// 加上这一句是避免连接器不载入c的运行时浮点库,参见《c专家编程》
float c = 1.f;
fllwt 2008-05-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 Chiyer 的回复:]
scanf
之前使用一下浮点运算,付值什么的都可以

比如

C/C++ code#include"stdio.h"voidmain()
{floatb[10][10]={0.0};
scanf("%f",&b[0][0]);
}
[/Quote]
记得书上说,如果数组不初始化,那么他们都被默认赋值为0,你所说的和书上说的冲突么?
NKLoveRene 2008-05-08
  • 打赏
  • 举报
回复
我刚才特意用dev c++试了
fllwt 2008-05-08
  • 打赏
  • 举报
回复
请问你们的机子调试 都没问题么?
加载更多回复(11)
炎热的夏季已经过去,家乡想必也要开始落叶了。如果我是小学生,让我以《秋》为题目作文,开头一定是“秋天是收获的季节”。是的,经过了春天的骚动,夏季的彷徨,来到了秋。这是新生报到的季节,动物贮藏食物的季节,马上就到十一长假的季节,这个季节更是收获的季节。 我们在播种时,势必首先考虑收成。种庄稼如此,学习语言更是如此。于是,“语言之争”是各个编程论坛必定讨论的话题,很多甚至是“X经”话题。对此,我的观点是:语言没有好坏之分,只有顺手不顺手和你能发挥到什么程度的问题。我们没有必要追求最新,“最先进”的编程方式,只需要学习好力所能及的语言。 VC的无所不能缺点是繁杂,稍有不慎就不知道什么地方出了包;VB常常被人耻笑过于简单,发布之后要带上一个“仓库”;Delphi虽然有快速开发的优势,但却姥姥不疼舅舅不爱的日渐西山…… 其实对于大多数人来说,我们使用什么应该是需求决定而不是语言本身决定需求,比如:我们希望自动根据数据生成表格,没有必要非用Delphi VC 调用 COM ,我们用用VBA就好了。因此,眼中只有那三种基本结构:判断 循环 跳转就差不多了,再高级一点,弄清楚什么是面向对象面向过程,随便一门语言都不会逃出这点东西。 我很佩服俄罗斯的软件,他们就是将语言工具发挥到极致的例子。比如:我在网上搜索到DOS下硬盘速度测试软件,竟然是Pascal编写的。 至于“学习好力所能及的语言”,我的意思是如果你身边有C语言高手不妨向他请教或者同他切磋;如果你有学好数据结构的理想,不妨买一本Java描述数据结构的图书慢慢啃;如果你有网络数据库+界面的需求不妨考虑一下Delphi…… 因此,我的观点就是“语言没有好坏之分”,关键是你能掌握到什么程度。 当然,如果你能掌握汇编语言,这一切就更不在话下了。我很希望各位能够将学习语言当作乐趣,我们的杂志也将会以如何让读者在阅读中感到快乐感到成就感为目的。

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧