#include
void main()
{
FILE* fp;
fp=fopen("a.txt","r"); //只读形式,打开文件
char buffer[50];
do
{
fscanf(fp,"%s\r\n",buffer); //在文件里读一个char块
puts(buffer); //打印出来
} while (!feof(fp));
fclose(fp);
}
#include
void main()
{
FILE* fp;
fp=fopen("a.txt","r"); //只读形式,打开文件
char buffer[50];
do
{
fscanf(fp,"%s\r\n",buffer); //在文件里读一个char块
puts(buffer); //打印出来
} while (!feof(fp)); //判断读入的字符是否是最后一个(EOF是文本文件结束的标志)
fclose(fp); //关闭文件,这是对任何文件操作之后的步骤
}
#include
#include
#include
void main()
{
FILE* pFile = fopen("随机读取.txt","r");
if (!pFile){
printf("open file failed!\n");
return ;
}
fseek(pFile, 0, SEEK_END);
int iFileLen = ftell(pFile);//到这一步可以得到里面有多少个字符
rewind(pFile);
char* pFileBuf = (char*)malloc(iFileLen+1);
if (!pFileBuf){
printf("malloc failed!\n");
fclose(pFile);
return ;
}
memset(pFileBuf,'\0',iFileLen+1);
fread(pFileBuf, 1, iFileLen, pFile);
fclose(pFile);
for (int i=0; i
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>File Len is %d\n",iFileLen);
}