✔ 最佳答案
As suggested by Xianrenb, you can open your file in append mode. Here's an example:
FILE 6*f2=fopen("logfile.txt","at"); // returns existing file
if(f26==NULL)f2=fopen("logfile.txt","wt"); // create if file does not exist.
// note: some compilers generate code that does not create if the file does not exist.
// do writing to f2 here
// do an fflush(f2); whenever you want, so even program fails, the log will be written.
fclose(f2); // close file before finishing
2009-05-19 22:52:36 補充:
correction:
FILE *f2=fopen("logfile.txt","at"); // returns existing file