// VC++6.0 环境编译这么简单的console程序也不能运行!?
// 编译通过,出现运行错误:
//           runtime error R6002
//           - floating point not loaded
// 升级到sp5问题依旧,但是我用Borland CB就正常得很。
// (VC++6.0 安装绝对正确,换机子问题依旧)// File: test.cpp
#include<stdio.h>
void main()
{
  float x[2][5];
  FILE *fp=fopen("cccc.txt","rt");
  if(fp)
  {
    int i;
    for(i=0; i<5; i++)
  fscanf(fp," %f %f ", x[0]+i,x[1]+i);//运行错,换成下面一行也错
    //fscanf(fp," %f %f ", &x[0][i],&x[1][i]);
  fclose(fp);
   // 但是我加上后面两行重新编译,没有错误了。
   // for(i=0; i<5; i++)
   // printf(" %f %f ", x[0][i],x[1][i]);
  }
}
/* cccc.txt 的内容:
  1 2 3 4 5 6 7 8 9 0
*///产生问题的关键在哪儿? 如何正确解决?

解决方案 »

  1.   

    VC6的编译器太差劲了,装VC.NET试一试。
      

  2.   

    MSDN例子:
    #include <stdio.h>FILE *stream;void main( void )
    {
       long l;
       float fp;
       char s[81];
       char c;   stream = fopen( "fscanf.out", "w+" );
       if( stream == NULL )
          printf( "The file fscanf.out was not opened\n" );
       else
       {
          fprintf( stream, "%s %ld %f%c", "a-string", 
                   65000, 3.14159, 'x' );      /* Set pointer to beginning of file: */
          fseek( stream, 0L, SEEK_SET );      /* Read data back from file: */
          fscanf( stream, "%s", s );
          fscanf( stream, "%ld", &l );      fscanf( stream, "%f", &fp );
          fscanf( stream, "%c", &c );      /* Output data read: */
          printf( "%s\n", s );
          printf( "%ld\n", l );
          printf( "%f\n", fp );
          printf( "%c\n", c );      fclose( stream );
       }
    }
      

  3.   

    #include<stdio.h>
    void main()
    {
      float x[2][5];
      FILE *fp=fopen("cccc.txt","rt");
      if(fp)
      {
        int i;
        for(i=0; i<5; i++)
      fscanf(fp," %f %f ", x[0]+i,x[1]+i);
      fclose(fp);  }
    }我 编译没有错误.
      

  4.   

    from msdn:
    1. about scanf
    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.
    2. about printf
    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.   

    to qimz(不说废话) :
    你的代码和我一样,是编译通过,运行出错,你试试。
    to jruv(江城飞鸿):
    我用的是默认设置,你要不信试试看,我换了同事的机子问题依旧。
    确实会编译通过,运行出错。
      

  6.   

    float x[2][5];for......
    x[0]+i,x[1]+i这要不错那可真是ms错!
      

  7.   

    fscanf(fp," %f %f ", &x[0][i],&x[1][i]);这也是错的!!
      

  8.   

    fscanf(fp," %f %f ", &x[0][i],&x[1][i]);这也是错的!!
      

  9.   

    to: ndy_w(carpe diem)
    I can't catch your words in English, 
    could you explain it in Chinese?By the way, how to solve this "bug" easily?to: maoxianwang
    I got the same result like you: 
    "Compile and Link successfully, but Run Error."
      

  10.   

    下面的代码编译运行都通过
    void main()
    {
      float x[2][5];
      FILE *fp=fopen("e:\\cccc.txt","rt");
      if(fp)
      {
    for(int i=0;i<5;i++)
    {
    fscanf(fp,"%f %f",&x[0][i],&x[1][i]);
    printf("%f,%f\n",x[0][i],x[1][i]);
    }
    fclose(fp);
      }
    }
    不知道你为什么会错!
      

  11.   

    这段也没问题
    #include "stdafx.h"#include<stdio.h>
    void main()
    {
      float x[2][5];
      FILE *fp=fopen("e:\\cccc.txt","rt");
      if(fp)
      {
    for(int i=0;i<5;i++)
    {
    fscanf(fp,"%f %f",x[0]+i,x[1]+i);
    printf("%f,%f\n",x[0][i],x[1][i]);
    }
    fclose(fp);
      }
    }
    运行结果:
    1.000000,2.000000
    3.000000,4.000000
    5.000000,6.000000
    7.000000,8.000000
    9.000000,0.000000
    Press any key to continue
      

  12.   

    你去掉这句:
    printf("%f,%f\n",x[0][i],x[1][i]);
    再运行试试看?
      

  13.   

    你去掉这句:
    printf("%f,%f\n",x[0][i],x[1][i]);
    并且build==> clean
    再运行试试看?
      

  14.   

    ndy_w(carpe diem) 
    的意思是说MSDN上说的scanf系列的函数缺省是不会使用浮点数支持的,而printf系列的函数则会使用浮点数支持,所以你加上printf语句就没有问题的你在你的工程的设置的编译选项中加上/MD编译开关就可以解决这个问题了
      

  15.   

    补充一下,我把你的代码拷贝下来,保存成Test.cpp文件,用如下的编译命令编译连接后执行成功
    cl /MD Test.cpp /link
      

  16.   

    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.
    -------------------------------------------------------------------------------
    编译器为了尺寸优化,只在需要浮点时才加入浮点支持。而scanf格式串中的%f不能被编译器识别,因此浮点支持没有加入。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.
    -------------------------------------------------------------------------------
    在程序其他地方使用浮点数,导致浮点支持被加入。比如,你的printf,有浮点的参数。
      

  17.   

    fopen 以后加入一个判断语句  看看是不是读取文件失败 
    如果在调试时 文件应该放在工程目录下   不是的话  放到程序同目录下
      

  18.   

    我认为 maoxianwang(大大㊣BETAⅡ //楼主,请把分给猪) ( 是对的楼主的写法 是取地址不是数值拉
      

  19.   

    ndy_w(carpe diem)是对的,小弟获益匪浅
    to sdwtao(老王)建议回去再把c语言书多读两遍