文件输出
求大神知道 为什么10之前的数无法正常打出
/* 将 1 - 100 写入文件 然后倒序读出来 */
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
FILE* pfile = NULL;
int val = 0;
long cnt = 0L;
int i = 0;
// open the file
pfile = fopen( "abc.txt" , "w" );
if( !pfile )
{
fprintf( stderr , "can not open the file \n" );
exit( 1 );
}
// write the file
for( val = 1 ; val <= 100 ; ++ val )
{
fwrite( &val , sizeof( int ) , 1 , pfile );
}
// close the file
fclose( pfile );
// open the file
pfile = fopen( "abc.txt" , "r" );
for( i = 1 ; i <= 100 ; ++ i )
{
fseek( pfile , - i * sizeof( int ) , SEEK_END );
fread( &val , sizeof( int ) , 1 , pfile );
printf( "%d " , val );
if( i % 10 == 0 ) printf( "\n" );
}
// close the file
fclose( pfile );
return 0;
}
...全文


