I'm really unsure on how to remove this warning from my code (it appears twice):
Passing argument 2 of 'getIndex' makes pointer from integer without a cast
The warning appears on line 36 and 37 of my code:
#include <stdio.h>
#include <string.h>
#define OPEN 1
#define CLOSED 0
/*
* Function to return index at which team ID input is stored
*/
int getIndex(char *id, char idList[50][50]) {
int k;
for (k=0; k<50; k++) {
if (strcmp(id,idList[k])==0) {
return k;
}
}
fprintf(stderr,"Error in getIndex function.\n");
return 0;
}
/*
* gets file pointer, reads line, determines winner of game, adds win/loss/tie
*/
void next_game(FILE *fp, char teamIDs[50][50], int *teamWins, int *teamLosses, int *teamTies) {
/* team IDs from file */
char team1[50];
char team2[50];
/* scores for each team from file */
int score1;
int score2;
/* index in array for each team */
int index1 = getIndex(team1,teamIDs[50][50]);
int index2 = getIndex(team2,teamIDs[50][50]);
/*
* gets line from file with both teams IDs and scores
* determines winner/tie and increments value in array at according index
*/
if (fscanf(fp,"%s %s %d %d",team1,team2,&score1,&score2)==4) {
if (score1 > score2) {
teamWins[index1]++;
teamLosses[index2]++;
}
else if (score1 < score2) {
teamWins[index2]++;
teamLosses[index1]++;
}
else {
teamTies[index1]++;
teamTies[index2]++;
}
}
else { /* No more input in file */
fclose(fp);
}
}
/*
* Function to print out league summery from arrays in columns
* Takes file that links team ID with team name
*/
void arrayPrint(FILE* fp, int win[], int loss[], int tie[]) {
char id[50];
char name[25];
int i=0;
/* prints columns */
printf("<TEAM NAME>\t<NUMBER OF WINS>\t<NUMBER OF LOSSES>\t<NUMBER OF TIES>\t<WINNING PERCENTAGE>\n");
while (fscanf(fp,"%s %s",id,name)==2) {
printf("%s/t%d/t%d/t%d/t%d%%\n",name,win[i],loss[i],tie[i],(win[i]/loss[i])*100);
i++;
}
}
int main(int argc, char* argv[]) {
/* Displays error message if 2 files are not included in command line */
if (argc%3 != 0) {
fprintf(stderr,"Error in %s main function. Must take 2 files as input.\n",argv[0]);
return -1;
}
/* stores each team's wins/losses/ties in a specific index */
int teamWins[50] = {0};
int teamLosses[50] = {0};
int teamTies[50] = {0};
/* stores team names (index for team name is same for index for that team's win/loss/tie record) */
char teamIDs[50][50];
/* getting array of all team IDs */
char tempID[50];
char tempName[25];
int j;
FILE *teams = fopen(argv[2], "r");
for (j=0; fscanf(teams, "%s %s",tempID,tempName)==2; j++) {
strcpy(teamIDs[j], tempID);
}
FILE *gameResults = fopen(argv[1],"r");
/* cycling games, adding wins and losses */
while (gameResults != NULL) {
next_game(gameResults,teamIDs,teamWins,teamLosses,teamTies);
}
/* printing end result */
arrayPrint(teams, teamWins, teamLosses, teamTies);
return 0;
}
Any help is much appreciated.
Thanks,
Michael

New Topic/Question
Reply




MultiQuote





|