So I'm trying to read a text file and at the start of each line is a timestamp, for example
02:04 xxxxxxxxxxxxxxxxxxxxxx
This is the function that I've created,
Code:
int check_clicks(char *str, char heroes[10][20], char players[10][20], char hero_names[10][20]) {
char getLine[1024];
FILE *fp;
int i,j,ID,minutes,seconds,count=0;
char player[20],name[20],hex[10],hero[20];
fp = fopen(str, "r");
if(fp == NULL) {
printf("Missing log file\n");
exit(20);
}
while(fgets(getLine, 1024, fp) != NULL) {
if(sscanf(getLine, "%d:%2d %s %s %s %*s %*s %*s %s",&minutes,&seconds,player,name,hex,hero)==6) {
if((minutes>=2)&&(seconds>=15)) {
break;
}
if((strcmp(player, "Player:")==0)&&(strcmp(hex,"0x19:")==0)) {
for(j=0;j<10;j++) {
if(strcmp(players[j],name)==0) {
ID = j;
}
}
for(i=0;i<10;i++) {
if(strcmp(heroes[i],hero)==0) {
if((ID<5)&&(i>4)) {
printf("%s(%s) clicked on %s(%s) at 0%d:%2d\n",players[ID],hero_names[ID],players[i],hero_names[i],minutes,seconds);
count += 1;
}
else if((ID>4)&&(i<5)) {
printf("%s(%s) clicked on %s(%s) at 0%d:%2d\n",players[ID],hero_names[ID],players[i],hero_names[i],minutes,seconds);
count += 1;
}
}
}
}
}
}
return count;
}
Now when i test my program out whenever there is a 0 it just produces whitespace.
Eg.
R3D_Drag0n(Shadow Fiend) clicked on CMW_(Storm Spirit) at 01: 8
Now as I'm only looking at the first 2 minutes and 15 seconds, I have manually put a 0 in front of the minutes part, however %2d does not produce "08" but " 8" as you can see.
Any help much appreciated.