#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就是你想要的小数了。
具体我这里就不写了,你自己思考下。
全部