我的代码目前正在消耗日志文件输出的字符,我不知道确切的原因。
FILE* theLog;
char filename[150];
theLog = fopen(filename, "w");
fprintf(theLog, "Blah Blah Blah");
time_t t = time(NULL);
struct tm tm = *localtime(&t);
fprintf(theLog, " Time: %d-%d-%d %d:%d:%dn", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
fclose(theLog);
FILE* fp = fopen(((Start *)start)->logFile, "a");
fprintf(fp, "More Stuff");
fclose(fp);
我的输出应该是这样的:"Blah Blah Blah Time: 2015-6-1 19:56:48 uff"
"More Stuff"由于某种原因被消耗/覆盖/消失。
代码用
截断文件theLog = fopen(filename, "w");
// w truncate to zero length or create text file for writing
使用"a"
追加
theLog = fopen(filename, "a");