Originally Posted by
quzah
w - truncate the file and start over (start with the file pointer at the beginning)
a - append on the end of the file (start with the file pointer at the end)
You can use a, but you need to rewind so you can start at the beginning. Alternately, you could use something like r+ which would open for reading and writing, and start at the beginning of the file.
Quzah.
Thanks for your reply.
I have used rewind() function before,but it failed still.The b.bin is appended to the tail of a.bin.
Code:
FILE* fa,*fb;
if((fb=fopen("b.bin","rb")) == NULL )
return false;
if((fa=fopen("a.bin","ab"))== NULL )
return false;
unsigned char buff[512];
memset(buff,0,512);
fread(buff,512,1,fb);
rewind(fa);
fwrite(buff,512,1,fa);
fclose(fa);
fclose(fb);
according to your tip,I open a.bin using "r+b",and it works this time.
So thank u again.But i am still confused why the rewind function dose not work.