#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
time_t t;
struct tm *info;
int line=0;
char c;
FILE *fp=fopen("./time.txt","a+");
if(NULL==fp){
return -1;
}
while(EOF!=(c=fgetc(fp))){
if('\n'==c){
line++;
}
}
while(1){
t=time(NULL);
info=localtime(&t);
if(NULL==info){
return -2;
}
line++;
fprintf(fp,"[%d] %d-%02d-%02d %02d:%02d:%02d\n",line,\
info->tm_year+1900,info->tm_mon+1,info->tm_mday,\
info->tm_hour,info->tm_min,info->tm_sec);
sleep(1);
fflush(fp);
}
fclose(fp);
return 0;
}