2011-01-09 14:41:10,421 INFO [rbe] - 开始测试时间:1294555266854
2011-01-09 15:26:25,550 INFO [创建文件] - 。。。。。。
2011-01-09 15:26:26,307 INFO [RBe] - 下一个请求:36883总共时间:273610039
2011-01-09 15:26:42,552 INFO [rbe] - 开始测试时间:1294558002319
2011-01-09 16:12:12,813 INFO [创建文件] - 。。。。。。
2011-01-09 16:12:18,931 INFO [RBe] - 下一个请求:36968总共时间:274577307
2011-01-09 16:12:38,809 INFO [rbe] - 开始测试时间:1294560758652
2011-01-09 16:57:53,908 INFO [创建文件] - 。。。。。。
2011-01-09 16:57:54,512 INFO [RBe] - 下一个请求:36761总共时间:271887638
2011-01-09 16:58:12,004 INFO [rbe] - 开始测试时间:1294563491763
2011-01-09 17:43:23,482 INFO [创建文件] - 。。。。。。
2011-01-09 17:43:25,657 INFO [RBe] - 下一个请求:36909总共时间:275605555
2011-01-09 17:43:43,574 INFO [rbe] - 开始测试时间:1294566223411
2011-01-09 18:28:55,219 INFO [创建文件] - 。。。。。。
如何读取第三行和第一行的时间差,并用第三行的请求数除以时间差?循环读取整个文件。
#include <stdio.h>
#include <string.h>
#include <time.h>
#include<stdlib.h>
int iYear=0,iMonth=0,iDay=0, iHour=0,iMinute=0,iSecond=0;
void Get_Time(char* Buf)
{
//获得年,月,日
char *pTmp,szBuf[21];
strcpy(szBuf,Buf);
pTmp=strchr(szBuf,'-');
char szYear[5],szMonth[3],szDay[3];
char* p=szBuf,*p1=szYear;
while (p != pTmp)
{ *p1=*p;p++;p1++;
}
*pTmp=',';
pTmp=strchr(szBuf,'-');
p1=szMonth;p++;
while (p != pTmp){
*p1=*p;p++;p1++;
}
*pTmp=',';
pTmp=strchr(szBuf,' ');
p1=szDay;p++;
while (p != pTmp){
*p1=*p;p++;p1++;
}
//获得时间
char szHour[3],szMinute[3],szSecond[3];
*pTmp=',';
pTmp=strchr(szBuf,':');
p1=szHour;p++;
while (p != pTmp){
*p1=*p;p++;p1++;
}
*pTmp=',';
pTmp=strchr(szBuf,':');
p1=szMinute;p++;
while (p != pTmp){
*p1=*p;p++;p1++;
}
*pTmp=',';
pTmp=strchr(szBuf,':');
p1=szSecond;p++;
while (p != pTmp && *p != '/0'){
*p1=*p;p++;p1++;
}
iYear=atoi(szYear);iMonth=atoi(szMonth);iDay=atoi(szDay);
iHour=atoi(szHour);iMinute=atoi(szMinute);iSecond=atoi(szSecond);
}
void main()
{
FILE *fp1, *fp2;
char f[200];
int i = 0, j = 0, l = 0;
if ((fp1 = fopen ("e://data//ssoinfo.txt", "r")) == NULL)
{
printf ("cannot open the file!/n");
return;
}
if ((fp2 = fopen ("e://data//ssoinfo_data.txt", "w")) == NULL)
{
printf ("cannot open the file!/n");
return;
}
char array[80][80] = {0};
char array_time[80][80] = {0};
int p = 0;
int array_time_j = 0;
while ((fgets(f, 256, fp1 )) != NULL)
{
p++;
int count=0;
int count_time = 0;
for ( i=0; ; i++)
{
if (f[i] != ',')
{
array[j][count]=f[i];
count++;
}
else
break;
}
if (p%3 ==0)//读取第三个“:”后的请求数
{
int count_maohao = 0;
for ( i=0; ; i++)
{
if(f[i] == ':')
{
count_maohao++;
if (count_maohao == 3)
break;
}
}
for (int p = i+1; p<i+6; p++)
{
array_time[array_time_j][count_time] = f[p];
count_time++;
}
array_time_j++;
}
array[j][i] = '/0';
l++;//用来判断下面for(j=0; j<l; j++)
j++;
}
int a[100];
struct tm t;
time_t tValue;
for(j=0; j<l; j++)
{
Get_Time(array[j]);
t.tm_year=iYear-1900;
t.tm_mon=iMonth;
t.tm_mday=iDay;
t.tm_hour=iHour;
t.tm_min=iMinute;
t.tm_sec=iSecond;
t.tm_isdst=0;
tValue = mktime(&t)%1000000;
a[j] = tValue;
//printf("%d ", iYear);
//printf("%d ", iMonth);
//printf("%d ", iDay);
//printf("%d ", iHour);
//printf("%d ", iMinute);
//printf("%d ", iSecond);
//printf("%ld/n", tValue);
}
int b[100], d=0;
for(j=0, i=2; i<l; i=i+3, j++)
{
b[j] = a[i] - a[i-2];
//printf("%d/n", b);
}
for(i=0; i<j; i++)
{
//printf("%d ", b[i]);
d = atoi(array_time[i]);
//printf("%d ", d);
//printf("%4.6f/n", b[i]/float(d));
fprintf (fp2, "%d %d %4.6f/n", b[i], array_time[i], b[i]/float(d));
}
fclose(fp1);
}