热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

fopen(data,r);这样就行了。下面是一个完整代码的例子。(取自微软MSDN)#includeFILE*stream,*stream2;voidmain(void)

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。

全部



推荐阅读
author-avatar
徐刚珠宝银饰_737
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有