Hi,
I used the code below to copy from one binary file to another, but the first file contains some EOF indicators (0xFF) as part of it, so the copy function actually copies the file until its first EOF indicator.
For example: if my file is {0x01, 0x02, 0x03, 0xFF, 0x01, 0x02, 0xFF, 0xFF}
then only {0x01, 0x02, 0x03}
will be copied to the new file. Any idea how to fix it (or maybe I'm missing something there...)
Code:
int Util_Copy_File(char* source, char* dest)
{
FILE *fs,*ft;
char ch;
char infile[100];
sprintf(infile, "%s", dest);
fs = fopen(infile,"r");
if(fs==NULL)
{
return -1;
}
ft = fopen(dest,"w");
if(ft==NULL)
{
fclose(fs);
return STATUS_FAIL;
}
while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}
fclose(fs);
fclose(ft);
return 0;
}
Thanks, Binyamin