#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
int main(int argc,char **argv)
{
FILE *fp;
time_t rawtime;
struct tm *info;
char ch[200];
int i;
int count=0;
fp = fopen("1.txt","a+");
if(fp == NULL){
perror("fp error");
exit(1);
}
while(fgets(ch,sizeof(ch),fp) != NULL){
count++;
bzero(ch,sizeof(ch));
}
while(1){
time(&rawtime);
info = localtime(&rawtime);
fprintf(fp,"%d %d-%d-%d %d:%d:%d\n",++count,info->tm_year+1900,info->tm_mon+1,info->tm_mday,info->tm_hour,info->tm_min,info->tm_sec);
printf("%d %d-%d-%d %d:%d:%d\n",count,info->tm_year+1900,info->tm_mon+1,info->tm_mday,info->tm_hour,info->tm_min,info->tm_sec);
fflush(fp);
sleep(1);
}
fclose(fp);
return 0;
}