上一篇:/kf/201205/130088.html
現在講些文件操作,一個個字節讀取文件,其實很簡單,相信大家都會,例子分開講,不然大家沒心情看很長的代碼
[cpp]
#include<stdlib.h>
#include<stdio.h>
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);//記得關閉文件
}