我需要在我的程序中读取一个完整的二进制文件到缓冲区,当我做它不能正常工作时:(,如何用所有二进制字符导入所有文件?
我想从二进制文件中读取一个字符串,但它再次没有读取我想要的所有字符串。
文件:
[®ןƒפ׃mױ<¬‰¯W
Aזםׁׂ0]:w‚A־}˜-]—F7§c.®4¡9׳vhֳ7 ןעGOֱ¸^£} ֻמךY&@ל÷ף יˆ»¼hYc,אxFxְ ׃ /=%y׳י×®m«₪"³P UײIE,Lעׂ“ ֽ₪4Cִֺ׀¯jך_GX&j’=Xr׀¶Fש`<ֳ¿6ֿנסv״›^smNYֵ›@ORת»ty5¼©`f¾| סה/:‹¹s׀ןZ½q\¢ַסס,Kˆֿ<»¦ֱWI–Dµ@₪ֲֻ[!Hoנ>¥
„¢דת\‰jֶק³lב’’`…־°ׂ-ץַˆ/7¬!8ם‰66]ן›Rװֶ~‰50¶
%ֺץYָעך”a¢s˜–›*ק·צkWnTPxC¬#«ץZב₪ָ€זo[ֻכֻּ00}¨לgֶˆVַ₪°p§צ‘שw¾ו½״Y.״tPן QNּoי±¯fGָֹ†]»)LY2&joדעB ¶.ׂ
8+U£־I;ײsE!מ¼כ“¹׳־הֶמ½]’²‚iy?r·*ח׳גֺפ
守则:
void main()
{
int size;
FILE * file1;
file=fopen("file","rb");
char * buff;
fseek(file,0,seek_end);// calculating the length of the file
size=ftell(file)+1;
fseek(file,0,seek_set);
buff=(char *)malloc(sizeof(char)*size));
fread(buff,1,size,file);// this line isn't working,I have a file with
// a size of 495 but it's reads only 5 elements.
free(buff);
}