getGameInfo
的定義給出了自身原型的衝突類型錯誤。函數定義衝突類型與原型
#include <math.h>
#include <stdio.h>
//FUNCTION PROTOTYPES============================================
//print report title and column headers
void printHeaders(int year, int month, int day);
//print game info and footer with averages
void printGameInfo(int year, int month[], int day[], int auscore[], int oppscore[], int numGames);
//print footer with average and larges point spread
void printFooter(int auscore[], int oppscore[], int numGames);
//open and read file into 1D arrays and return #games
int getGameInfo(FILE* filePtr, int month[], int day[], int auscore[], int oppscore[]);
//return the average on an int array
double mean(int array[], int count);
int main()
{
int month[15], day[15], auscore[15], oppscore[15], numGames;
#define thisyear 2017
#define lastyear 2016
FILE *THISYEAR; // pointer to data file
FILE *LASTYEAR; // pointer to data file
THISYEAR = fopen("Auburn Football 2017.txt", "r");
LASTYEAR = fopen("Auburn Football 2016.txt", "r");
if (THISYEAR == NULL || LASTYEAR == NULL) //bad open
printf("Error opening input file.");
else //good open
{
getGameInfo(LASTYEAR, month, day, auscore, oppscore);
printGameInfo(lastyear, month, day, auscore, oppscore, numGames);
//rest of program ...
}
}
int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[])
{
int numGames;
for (numGames = 0; numGames < 14; numGames++)
{
fscanf(filePtr, "%d", &month[numGames]);
fscanf(filePtr, "%d", &day[numGames]);
fscanf(filePtr, "%d", &auscore[numGames]);
fscanf(filePtr, "%d", &oppscore[numGames]);
}
return numGames;
}
void printGameInfo(int year, int month[], int day[], int auscore[], int oppscore[], int numGames)
{
printHeaders(year, month[numGames], day[numGames]);
printFooter(auscore, oppscore, numGames);
}
void printHeaders(int year, int month[numGames], int day[numGames])
{
printf("%d Auburn Football Season as of %d/%d", &year, &month[numGames], &day[numGames]);
printf("Date Auburn Opp");
}
void printFooter(int auscore[], int oppscore[], int numGames)
{
double avoppscore, avauscore;
avoppscore = mean(oppscore, numGames);
avauscore = mean(auscore, numGames);
printf(" Ave score %lf %lf ", avauscore, avoppscore);
}
double mean(int array[], int count)
{
int i;
double average, sum = 0;
for (i = 0; i < count; i++)
{
sum += array[i];
}
average = sum/count;
return average;
}
函數:'printHeaders()'有一個未使用的參數:'month'建議消除該參數(或修復該函數以使用該參數,類似的考慮因素存在於參數'日'中 – user3629249
類似於:'' fscanf(filePtr,「%d」,&month [numGames]);'正在傳遞一個'** int'參數,但是應該傳入一個'* int'參數建議刪除多餘的'&' – user3629249
關於:'void printHeaders int year,int month [numGames],int day [numGames])'變量:'numGames'沒有被定義,在這裏建議:void printHeaders(int numGames,int year,int month [],int day [])調用'fopen()'時修改原型和所有對此函數的調用以匹配 – user3629249