正文

TC的一个BUG2006-12-26 17:10:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wolfelite/21961.html

分享到:

#include<stdio.h>     main()     {         static   float   f[3][4];         int   i,j;         for(i=0;i<3;i++)             for(j=0;j<4;j++)                 scanf("%f",&f[i][j]);             for(i=0;i<3;i++)         {             for(j=0;j<4;j++)                 printf("%f   ",f[i][j]);             printf("\n");         }     }     scanf:floating   point   formats   not     linked     Abnormal   program   termination   如果你用的编译器是TC的活,我们经常会碰到上面的问题!!   实则是:   Turbo-C的问题Turbo   C(TC)系统的浮点连接错误       用TC-2.0系统编写小的C程序,如果程序里用到浮点输入,有时运行中会出现下面错误信息:       scanf   :   floating   point   formats   not   linked       Abnormal   program   termination       这个错误信息的意思是:scanf的浮点格式转换程序没有连接。       TC开发时(80年代)DOS下的存储资源紧缺,因此TC在编译时尽量不加入无关部分。在没发现需要做浮点转换时,就不将这个部分安装到可执行程序里。但有时TC不能正确识别实际确实需要浮点转换,因此就会出现上面错误。           解决方法:设法告诉TC需要做浮点数输入转换。下面例子里增加了一个double变量并用它输入。       大程序里由于变量很多,只要有了线索,TC就会把浮点转换连上,因此反而不常遇到这个问题。                   /*   能导致出现运行错误的程序例子。       在这里用的一个结构数组,结构里面有double类型的成分,TC不能正确识别和处理,因此会导致上述问题。*/       #include   <stdio.h>       #define   NUM   4       struct   entry   {               int   inum;         /*   商品编号   */               int   pc;             /*   件数           */               double   price;/*   价钱           */       }   st[NUM];               /*   st是个商品表   */       int   main   ()   {               int   i;               for   (i   =   0;   i   <   NUM;   i++)                       scanf("%d   %d   %lf",   &st[i].inum,   &st[i].pc,   &st[i].price);               for   (i   =   0;   i   <   NUM;   i++)                       printf("total   price   of   item   %d:   %f\n",                                       st[i].inum,   st[i].pc   *   st[i].price);               return   0;       }       /*   这个程序编译正常,运行中会出现上面错误信息   */                   /*   修改的程序,其中增加了一个double变量x。问题就解决了   */       #include   <stdio.h>       #define   NUM   4       struct   entry   {               int   inum;               int   pc;               double   price;       }   st[NUM];       int   main   ()   {               int   i;               double   x;               for   (i   =   0;   i   <   NUM;   i++)   {                       scanf("%d   %d   %lf",   &st[i].inum,   &st[i].pc,   &x);                       st[i].price   =   x;               }               for   (i   =   0;   i   <   NUM;   i++)                       printf("total   price   of   item   %d:   %f\n",                                       st[i].inum,   st[i].pc   *   st[i].price);               return   0;       }  

阅读(1826) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册