开发者

MFC problem to copy binary file

I want to copy a binary master file in a new binary file. This file contain nothing but have a predefined size (20000 lines).

Here what i'm doing:

     FILE *A_Lire;
     FILE *A_Creer;

A_Lire = fopen(MASTERPath,"rb");
A_Creer = fopen(PARTPRGPath, "wb");

fseek(A_Lire,0,SEEK_END);
int end = ftell(A_Lire);

char* buf = (char*)malloc(end);

fread(buf,sizeof(char),end,A_Lire);
fwrite(buf,sizeof(char),end,A_Creer);

fclose(A_Creer);
fclose(A_Lire);

Th开发者_开发百科is code create the new file with the good size but this is not exactly the same file because I'm not able to used this new file like the master. Something is different, maybe corrupted, maybe the way to write in the file ???

Do you have any idea ???

I think this is MFC code

Thanks,


when you do fseek(..SEEK_END), the position inside the opened file is at the end, whenever you call fread, you are getting 0 bytes as you're at the end.

Just do a rewind after that:

fseek(A_Lire,0,SEEK_END);

int end = ftell(A_Lire);

fseek(A_Lire,0,SEEK_SET);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜