I am trying to take data from a CSV file containing statistics on every fixture from the 2013/2014 English Premier League season. I am trying to take the data that is valid to me so I can create a finalised league table from the results of the fixtures. Here is what two lines from the file look like:
2013-08-17,Arsenal,Aston Villa,1-3,1-1
2013-08-25,Cardiff,Man City,3-2,0-0
As you can see "2013-08-17" and "2013-08-25" are at index 0, "Arsenal" and "Cardiff" are at index 1 etc. I am using indexes 1 to 4 to help make my table and have started by splitting up each index at the comma so they print out as such:
Arsenal
Aston Villa
1-3
1-1
I have gone on to tokenise indexes 3 and 4 at the hyphen(which are "1-3" and "1-1" in the example above) so each number prints out on a separate line like this:
H:1
H:1
F:1
F:3
The numbers with "H:" in front are in the same pointer and the numbers with "F:" in front are all in another pointer, but I need the two numbers in H: to go in separate identifiers and the same for the numbers in F: and need that done for every fixture. I have been struggling to do that though and wondered if anyone could help?! Here is my function in which I am tokenising my data so you can see what's going on:
void tokenise(char *line)//the pointer line holds each line as the file as it is read in
{
char homeTeam[32];
char awayTeam[32];
char fullScore[12];
char halfTimeScore[12];
char *token = strtok(line, ",");//the pointer *token is given the lines to hold
int i = 0;
while(token != NULL)
{
switch(i)
{
case 1:
strcpy(homeTeam, token);//splitting indexes up at comma
break;
case 2:
strcpy(awayTeam, token);
break;
case 3:
strcpy(fullScore, token);
break;
case 4:
strcpy(halfTimeScore, token);
break;
default:
printf("");
}
i++;
token = strtok(NULL, ",");
}
char *halfTimeScoreToken = strtok(halfTimeScore, "-");//*halfTimeScoreToken is the pointer that holds the numbers with "H:" in front
while(halfTimeScoreToken != NULL)
{
printf("\nH:%s", halfTimeScoreToken);
halfTimeScoreToken = strtok(NULL, "-");
}
char *fullScoreToken = strtok(fullScore, "-");//*fullScoreToken is the pointer that holds the numbers with "F:" in front
while(fullScoreToken != NULL)
{
printf("F:%s\n", fullScoreToken);
fullScoreToken = strtok(NULL, "-");
}
}