Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Es ( 19 years ago )
struct TimeStamp
{
int h;
int m;
int s;
};
int TimeDiff(TimeStamp firstTime, TimeStamp secondTime)
{
int a, b, c;
if(firstTime.h == -1)
return 0;
if((firstTime.h != 0) && (secondTime.h == 0))
secondTime.h = 24;
a = secondTime.h - firstTime.h;
if((a > 1) || (a < 0))
return 0;
a = firstTime.h * 3600 + firstTime.m * 60 + firstTime.s;
b = secondTime.h * 3600 + secondTime.m * 60 + secondTime.s;
c = b - a;
if (c < 0)
return 0;
if (c > 600)
return 5;
return c;
}
int main(int argc, char *argv[])
{
TimeStamp thisTime, lastTime;
int totalTime;
char buff[1024];
lastTime.h = -1;
totalTime = 0;
while(!feof(logFile))
{
fgets(buff, 1024, logFile);
if(buff[0] == '[')
{
sscanf(buff, "[%2d:%2d:%2d", &(thisTime.h), &(thisTime.m), &(thisTime.s));
totalTime += TimeDiff(lastTime, thisTime);
lastTime = thisTime;
}
}
int totalH, totalM, totalS;
totalH = (int) (totalTime/3600);
totalM = (int) ((totalTime - totalH * 3600) / 60);
totalS = totalTime % 60;
printf("%d Seconds
", totalTime);
printf("%d:%2d:%2d
", totalH, totalM, totalS);
return 0;
}
Revise this Paste