C语言读取txt中小数问题
我需要用C语言实现从文本里面读取小数的功能,每读到一个小数后,就将它赋值给一个float型变量,因为我要对这个float变量进行处理。然后再读下一个小数,直到结束。补充:...
我需要用C语言实现从文本里面读取小数的功能,每读到一个小数后,就将它赋值给一个float型变量,因为我要对这个float变量进行处理。然后再读下一个小数,直到结束。
补充:不是将这些小数打印出来。
-0.55608481122180820000
-0.54904576297849417000
-0.54200671473518014000
-0.53496766649186611000
-0.52792861824855208000
-0.52088957000523806000
-0.12670286837965250000
-0.16189810959622264000
-0.16893715783953667000
-0.11966382013633847000
0.47865528054535389000
0.69686577608808875000
0.40826479811221361000
0.47161623230203986000
-0.15485906135290861000
-0.16893715783953667000
-0.14782001310959458000
-0.83060769271105528000
-0.21821049554273486000
-0.21117144729942083000
-0.20413239905610681000
-0.19709335081279278000
-0.19005430256947875000
-0.18301525432616472000
-0.17597620608285069000
-0.67574863135814667000
-0.16893715783953667000
-0.16189810959622264000
-0.15485906135290861000
-0.14782001310959458000
-0.14078096486628056000
-0.13374191662296653000
-0.12670286837965250000
-0.67574863135814667000
-0.11966382013633847000
-0.11262477189302444000
-0.10558572364971042000
-0.09854667540639638900
-0.09150762716308236100
-0.08446857891976833300
-0.67574863135814667000 展开
补充:不是将这些小数打印出来。
-0.55608481122180820000
-0.54904576297849417000
-0.54200671473518014000
-0.53496766649186611000
-0.52792861824855208000
-0.52088957000523806000
-0.12670286837965250000
-0.16189810959622264000
-0.16893715783953667000
-0.11966382013633847000
0.47865528054535389000
0.69686577608808875000
0.40826479811221361000
0.47161623230203986000
-0.15485906135290861000
-0.16893715783953667000
-0.14782001310959458000
-0.83060769271105528000
-0.21821049554273486000
-0.21117144729942083000
-0.20413239905610681000
-0.19709335081279278000
-0.19005430256947875000
-0.18301525432616472000
-0.17597620608285069000
-0.67574863135814667000
-0.16893715783953667000
-0.16189810959622264000
-0.15485906135290861000
-0.14782001310959458000
-0.14078096486628056000
-0.13374191662296653000
-0.12670286837965250000
-0.67574863135814667000
-0.11966382013633847000
-0.11262477189302444000
-0.10558572364971042000
-0.09854667540639638900
-0.09150762716308236100
-0.08446857891976833300
-0.67574863135814667000 展开
1个回答
2008-06-04
展开全部
//---------------------------------------------------------------------------
#include <stdio.h>
int main(void)
{
FILE *fp;
float w;
fp=fopen("c:\\a.txt","r");/*假设数据位于c:\a.txt文件中,具体位置可在此修改*/
while (!feof(fp)){
fscanf(fp,"%f",&w);/*逐一从fp文件中读取数据,需要指明的是C的内置类型无法达到你要求的精度*/
printf("%f\n",w);/*输出*/
}
fclose(fp);/*关闭文件*/
return 0;
}
//---------------------------------------------------------------------------
#include <stdio.h>
int main(void)
{
FILE *fp;
float w;
fp=fopen("c:\\a.txt","r");/*假设数据位于c:\a.txt文件中,具体位置可在此修改*/
while (!feof(fp)){
fscanf(fp,"%f",&w);/*逐一从fp文件中读取数据,需要指明的是C的内置类型无法达到你要求的精度*/
printf("%f\n",w);/*输出*/
}
fclose(fp);/*关闭文件*/
return 0;
}
//---------------------------------------------------------------------------
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询