FILE *fp;
long lSize;
char *c;
size_t result;
fp=fopen(rbuf,"rb");
if(!fp)
{
printf("Can't open File abc.txt!");
}
fseek(fp, 0, SEEK_END);
lSize=ftell(fp);
rewind(fp);
c=(char *)malloc(sizeof(char)*lSize);
if(c==NULL)
{
printf("Memory error!");
}
result=fread(c,1,lSize,fp);
if(result!=lSize)
{
printf("Reading error!");
}
printf("%s",c);
fclose(fp);
free (c);
//前面的rbuf文件名是正确的,文件是.txt文件,内容是“我们是中国人,我们爱自己的祖国!”。
输出的结果如图: