原来的log显示
代码修改后的log显示,由于目前只关注时间格式,目前的代码有待完善。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE * fp_r, *fp_w;
int len;
char buf[4096] = {0};
char str[1024] = {0};
char *res, *res1, *res2;
char *linestr = "\n";
char *tempstr = NULL;
int tempnum = 0 ,num =0;
fp_r = fopen("E:\\Test_log\\input.txt","rb+");
if(fp_r == NULL){
printf("fopen fp_r error! \n");
return -1;
}
fp_w = fopen("E:\\Test_log\\output.txt","wb+");
if(fp_w == NULL){
printf("fopen fp_w error! \n");
return -1;
}
while(fgets(buf, 4096,fp_r)!=NULL){
res = buf;
while(*res !='2'){ /*保证首行是2019开头不是空格开头*/
res++;
}
res1 = strstr(res,":");
res1++;
res2 = strstr(res1,":");
tempnum =(*(res2+4))-'0'; /*res2+4为毫秒的位置*/
printf("tempnum1= %d ",tempnum);
if (tempnum>=0 && tempnum <=9){
num = tempnum;
}
tempnum =(*(res2+5))-'0';
printf("tempnum2= %d ",tempnum);
if (tempnum>=0 && tempnum <=9){
num = num*10+ tempnum;
}
tempnum =(*(res2+6))-'0';
printf("tempnum3= %d ",tempnum);
if (tempnum>=0 && tempnum <=9){
num = num*10+ tempnum;
}
printf("num = %d\n",num); /*毫秒值*/
if(num >=10 && num <= 99){ /*将两位毫秒数变为3位毫秒数,如056*/
*(res2+4 )= '0';
tempstr =itoa(num,str,10);
memcpy(res2+5,tempstr,2);
}
if(num >=0 && num <= 9){/*将一位毫秒数变为3位毫秒数,如007*/
*(res2+4 ) = '0';
*(res2+5 ) = '0';
tempstr =itoa(num,str,10);
memcpy(res2+6,tempstr,1);
}
*(res2+7 ) = ' ';
*(res2+8 ) = ' ';
len = strlen(res);
memcpy(res+len, linestr, strlen(linestr));
fputs(res, fp_w);
memset(buf, 0, sizeof(buf));
res = NULL;
res1 =NULL;
res2 = NULL;
num = 0;
tempnum = 0;
}
return 0;
}