莫名其妙的文件读取错误 fread() 函数
我的测试程序:
#include "stdio.h"
#include "malloc.h"
int main()
{
long outf_len=0;
FILE * outf;
outf=fopen("D:\\Outdata.txt","r");
if(!outf)
{
printf("open file err\n");
return 0;
}
fseek(outf,0,SEEK_END);
outf_len=ftell(outf);//得到文件大小
printf("%d\n",outf_len);
char * outf_buff=(char *)malloc(outf_len);
fseek(outf,0,SEEK_SET);
int size=fread(outf_buff,sizeof(char),outf_len,outf);
printf("%d\n",size);
printf("%s\n",outf_buff);
return 1;
}
文件中的内容是一段乱码,是用自己成程序加密的。现在遇到的问题是,读取这个文件时只能读取前面的一段数据。而且我本想复制下这个文件的内容贴上来,但是复制到的居然也只是我用程序读到的那一小段数据。
是格式的问题吗?我是用写字板打开的。