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;
}
答案 0 :(得分:2)
这是因为你的声明调用指针,而你的定义调用双指针。
比较您的声明和定义:
int getGameInfo(FILE* filePtr, int month[], int day[], int auscore[], int oppscore[]);
<强> VS 强>
int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[])
像int *month[]
这样的东西相当于int **month
,而像int month[]
这样的东西在作为参数传递给函数时等同于int *month
。见this answer。
要修复,您可以将声明更改为以下内容:
//open and read file into 1D arrays and return #games
int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[] );
或者,将您的功能定义更改为以下内容:
int getGameInfo( FILE* filePtr, int month[], int day[], int auscore[], int oppscore[])
{
...
}
根据该功能的作用来判断,我相信你想要第二种选择。
答案 1 :(得分:0)
每次编译器抛出冲突类型错误比较函数原型和定义。
在这种情况下
原型
int getGameInfo(FILE* filePtr, int month[], int day[], int auscore[], int oppscore[]);
和定义
int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[])
正如您所看到的,名称为getGameInfo
的给定函数,参数2,3和4不匹配,因此错误。