Hi, Guys, problem solved, below is the source code, in case anyone running into the same problem, any suggestion to make it "prettier" is appreciated, thanks again.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define SIZE 50
#define CROPPED_SIZE 10
/* function prototype */
char * RemoveColon (char *dest, const char *src);
int main (int argc, char **argv) {
/* define buffer space for the file */
char string[SIZE];
char croppedString[SIZE];
FILE *pfile;
int i, previousNum=0, counter=0, timeGap;
char mytime[CROPPED_SIZE];
char *croppedTime = mytime;
/* open the existing file from input */
pfile = fopen (argv[1], "r");
while (fgets (string, SIZE, pfile) != NULL) {
strcpy (croppedString, string);
/* using sscanf to extract the string */
if (sscanf(croppedString, "%*[^-]-%*[^-]-%20[^ ]", mytime) == 1) {
/* zero out the unwanted characters */
for (i=18; i<SIZE; i++) {
croppedString[i] = '\0';
}
croppedTime = RemoveColon (croppedTime, mytime);
int convertedNum = atoi(croppedTime);
timeGap = convertedNum - previousNum;
if (timeGap < 0) {
convertedNum = convertedNum + 240000;
timeGap = convertedNum - previousNum;
}
if ((timeGap >= 10000) && (previousNum != 0)){
counter++;
printf("%s\n", string);
}
previousNum = convertedNum;
}
}
fclose (pfile);
return 0;
}
char * RemoveColon (char *new, const char *str) {
const char *p;
char *q;
for (p=str, q=new; *p != '\0';) {
if (*p != ':') {
*q = *p;
p++;
q++;
} else {
p++;
}
}
*q = '\0';
return new;
}
Thanks.
hc