#include <head.h>
int main(int argc, const char* argv[])
{
FILE* fp;
time_t ts;
struct tm* tm;
int i = 0;
int line = 0;
int ret = 0;
char ch;
if ((fp = fopen("./tim.txt", "a+")) == NULL) {
PRINT_ERR("fopen error");
}
if ((ts = time(NULL)) == -1)
PRINT_ERR("get time error");
if ((tm = localtime(&ts)) == NULL)
PRINT_ERR("chang time error");
//续写行号
while((ch = fgetc(fp))!=EOF){
if(ch == '\n'){
i++;
}
}
line = i;
while (1) {
ret = tm->tm_sec;
if ((ts = time(NULL)) == -1)
PRINT_ERR("get time error");
if ((tm = localtime(&ts)) == NULL)
PRINT_ERR("chang time error");
if (ret != tm->tm_sec) {
line++;
fprintf(fp, "%d.%d年%02d月%02d日 %02d:%02d:%02d week = %d\n", line, tm->tm_year + 1900, tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
fflush(fp);
}
}
fclose(fp);
return 0;
}