打开文件进行行编辑c语言,C中如何以只读方式打开文件打开后不能进行编辑 爱问知识人...

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。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值