#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
time_t curtime;
int count = 1;
FILE *fp = fopen("1.txt", "w");
if(fp == NULL)
{
perror("fopen");
return -1;
}
while(1)
{
time(&curtime);
fputs(ctime(&curtime), fp);
fflush(fp);
sleep(1);
printf("时间:%s\n", ctime(&curtime)); //以字符串形式输出localtime本地时间
printf("count:%d\n",count++);
}
fclose(fp);
return 0;
}