一个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了)
...全文
405 31 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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)

70,022

社区成员

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

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