#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
//不点赞的让你们飞起来
int main(int argc, char const *argv[])
{
time_t t;
struct tm *tm;
FILE *fp = fopen("test.txt", "a");
if (NULL == fp)
{
perror("fopen error");
return -1;
}
while (1)
{
time(&t);
tm = localtime(&t);
fprintf(fp, "%04d-%02d-%02d %02d:%02d:%02d\n",tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,tm->tm_hour+15, tm->tm_min, tm->tm_sec);
// 刷新文件流
fflush(fp);
// 休眠1秒钟
sleep(1);
}
fclose(fp);
return 0;
}