2017-11-04 2 views
0

의 정의가 충돌하는 유형 정의 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

'printHeaders()'에는 사용되지 않은 매개 변수가 있습니다 :'month' 해당 매개 변수의 제거를 제안하거나 해당 매개 변수를 사용하기위한 함수를 수정하십시오. 비슷한 고려 사항이 'day' 매개 변수에 해당합니다 .. – user3629249

+0

문은' fscanf (filePtr, "% d", 그리고 month [numGames]);'** int' 매개 변수를 전달하지만'* int' 매개 변수를 전달해야합니다 불필요한'&' – user3629249

+0

제거 제안 :'void printHeaders int numGames, int day [numGames])'변수 :'numGames'가 정의되지 않았습니다. 제안 : void printHeaders (int numGames, int year, int month [], int day []) 'fopen()'을 호출 할 때 프로토 타입과이 함수의 모든 호출을 – user3629249

답변

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[]) 

A와 인수로 전달할 때 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[]) 
{ 
    ... 
} 

을 그 함수가 무엇으로 판단, 저는 믿습니다 당신은 두 번째 옵션을 원합니다.

0

때마다 컴파일러는 충돌하는 유형 오류 함수 프로토 타입 및 정의를 비교합니다. 당신이 이름으로 주어진 함수의 getGameInfo 인수를 볼 수 있습니다이 경우에

프로토 타입

int getGameInfo(FILE* filePtr, int month[], int day[], int auscore[], int oppscore[]); 

및 정의

int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[]) 

2, 3, 4가 일치하지 않습니다 그러므로 오류.