设为首页 加入收藏

TOP

我的C/C++之路-011课(读取文件)
2014-11-24 00:33:09 来源: 作者: 【 】 浏览:31
Tags:C/C 之路 -011 读取 文件

上一篇:http://www.2cto.com/kf/201205/130088.html

现在讲些文件操作,一个个字节读取文件,其实很简单,相信大家都会,例子分开讲,不然大家没心情看很长的代码

[cpp]
#include
#include

void readFile()
{
FILE *file;//文件指针
char c;//一个个字符读取
file = fopen("c:\\test.txt","r");//打开文件
if(NULL==file)//判断是否打开成功
{
printf("can't open this file,make sure the file exist!!!\n");
exit(1);
}
puts("open file successful!!!");
puts("READ FILE NOW:");

c = fgetc(file);
while(c!=EOF)//文件尾的标志为EOF
{
putchar(c);
c = fgetc(file);
}
printf("\n");
fclose(file);//记得关闭文件
}


\



摘自 mzlqh的专栏
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇数组和指针背后――内存角度 下一篇数组定义已经自动初始化

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: