fopen( "data", "r" );这样就行了。下面是一个完整代码的例子。
(取自微软MSDN)
#include FILE *stream, *stream2;void main( void ){ ? int numclosed; ? /* Open for read (will fail if file "data" does not exist) */ ? if( (stream ?= fopen( "data", "r" )) == NULL ) ? ? ?printf( "The file 'data' was not opened
" ); ? else ? ? ?printf( "The file 'data' was opened
" ); ? /* Open for write */ ? if( (stream2 = fopen( "data2", "w " )) == NULL ) ? ? ?printf( "The file 'data2' was not opened
" ); ? else ? ? ?printf( "The file 'data2' was opened
" ); ? /* Close stream */ ? if( fclose( stream ) ) ? ? ?printf( "The file 'data' was not closed
" ); ? /* All other files are closed: */ ? numclosed = _fcloseall( ); ? printf( "Number of files closed by _fcloseall: %u
", numclosed );}
Output
The file 'data' was openedThe file 'data2' was openedNumber of files closed by _fcloseall: 1。
全部