How to overwrite text in file?

Hi, I have a question about controlling a file.

With MFC, I can overwrite stream with code blew.

f.Open(strFullPath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::typeBinary, &ex)

f.write(buffer, buffersize);

For instance, file called "A.txt" has "ABCDE" in it. Then it will be "KKCDE" when I put the text "KK" like this.

char buffer[2] = {'K','K'};
f.write(buffer, buffersize);

I want to make it out in C/C++ not in MFC.

So, I did like this.

FILE *f;

f = fopen(path, "a");
// I put "a" as a mode, and other modes don't work neither.
fseek(f,0,SEEK_SET);

fwrite(buffer, 1, buffersize, f);

the result is "ABCDEDD" not "KKCDE".(with "a" mode which means "append")
(with "w" mode, it will be "KK"(re-created))

I need to know how to overwrite text in file.

Any ideas?? Thanks.
try fopen(path,"wb")
I solved it out.

The problem was that i didn't put "flush()".

LOL Thanks anyways.
Topic archived. No new replies allowed.