0

the definition of getGameInfo gives a conflicting type error with the prototype of itself.

#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;
}
mch
  • 9,424
  • 2
  • 28
  • 42
  • the function: `printHeaders()` has a unused parameter: `month` Suggest elimination of that parameter (or fix the function to use that parameter. Similar considerations exist for the parameter `day`. – user3629249 Nov 06 '17 at 21:21
  • statements similar to: `fscanf(filePtr, "%d", &month[numGames]);` are passing a `**int` parameter but should be passing a `*int` parameter. Suggest removing the extraneous `&` – user3629249 Nov 06 '17 at 21:24
  • regarding: `void printHeaders(int year, int month[numGames], int day[numGames])` the variable: `numGames` is not defined, here. Suggest: `void printHeaders( int numGames, int year, int month[], int day[])` and modifying the prototype and all calls to this function to match – user3629249 Nov 06 '17 at 21:27
  • when calling `fopen()`, always check (!=NULL) the returned value to assure the operation was successful. If not successful, call `perror( "your text" )` so your text and the text from the OS on why the error occurred are displayed on `stderr`, then cleanup and call: `exit( EXIT_FAILURE );` to exit the program – user3629249 Nov 06 '17 at 21:32
  • in function: `main()`, after calling `getGameInfo()` and `printGameInfo()` need to call `fclose()` for each of the two open files – user3629249 Nov 06 '17 at 21:34

2 Answers2

2

It is because your declaration calls for pointers, while your definition calls for double pointers.

Compare your declaration and definition:

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

Something like int *month[] is equivalent to int **month, while something like int month[] is equivalent to int *month when passing as an argument to a function. See this answer.

To fix, you can change your declaration to the following:

//open and read file into 1D arrays and return #games
int getGameInfo(FILE* filePtr, int *month[], int *day[], int *auscore[], int *oppscore[] );

or alternatively, change your function definition to the following:

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

Judging by what that function does, I believe you want the second option.

Nik
  • 1,780
  • 1
  • 14
  • 23
0

every time compiler throws a conflicting type errors compare function prototype and definition.

in this case

prototype

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

and in definition

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

as you can see for a given function with name getGameInfo arguments 2,3 and 4 doesn't match hence the error.

asio_guy
  • 3,667
  • 2
  • 19
  • 35