c语言 读文件 小数,请用C语言解决问题一个文件,每行131个小数,共61行,如何用? 爱问知识人...

#include

#include

void main( void )

{ ?

? ? ? ?int ?count, total = 0; ?

? ? ? ?char buffer[100]; ? FILE *stream; ?

? ? ? ?if( (stream = fopen( "feof。

c", "r" )) == NULL ) ? ? ?

? ? ? ? ? ?exit( 1 ); ? /* Cycle until end of file reached: */ ?

? ? ? ? while( !feof( stream ) ) ?

? ? ? ? { ? ? ?/* Attempt to read in 10 bytes: */ ? ? ?

? ? ? ? ? ? ? ?count = fread( buffer, sizeof( char ), 100, stream ); ? ? ?

? ? ? ? ? ? ? ?if( ferror( stream ) ) ? ?

? ? ? ? ? ? ? ? { ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?perror( "Read error" ); ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?break; ? ? ?} ? ? ?/* Total up actual bytes read */ ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?total = count; ?

? ? ? ? ?} ?

? ? ? ? printf( "Number of bytes read = %d

", total ); ?

? ? ? ?fclose( stream );

}参考此例子将内容全部读入数组,建议数组用内存malloc申请,全部内容存储到一个数组中,然后对数组遍历,如果文件中小数是以空格或者制表符,逗号间隔,查找这些将每个数据分离开,然后进行转换,atof就是你想要的小数了。

具体我这里就不写了,你自己思考下。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值