C program 高手請入

2009-05-20 2:37 am
有冇辦法用C program時輸入D字入去D txt檔而唔刪除入面資料?
註:唔係C++!

回答 (2)

2009-05-20 6:49 am
✔ 最佳答案
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
2009-05-20 3:58 am
我想發問者可以在開 file 時選擇 append mode 吧?


收錄日期: 2021-04-13 16:37:50
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090519000051KK01193

檢視 Wayback Machine 備份