0

I am getting the following errors with my code, one of which I cant find a way to fix. I understand the declaration of a function type must match definition, but it does.

#include <stdio.h>
#include <math.h>

//Global Declarations
int input_win(void);
int input_scores(int,int);
void results(int,int,int,int);

int main()
{
  //Local Declarations
    int winNum;        //The number of points needed to win
    int scores[25];    //The array of scores
    int score_old = 0; //The second to most recent score input
    int score_new;     //The most recent score input
    int cnt_score = 1; //The count for input
    int cnt_won = 0;   //The count for games won
    int cnt_played =0; //The count for games played
  //Executeable Statements
    winNum = input_win();
    do
    {
      score_new = input_scores(cnt_score,cnt_won);
      if(score_new != -1)
      {
        if(score_new <= score_old)
        {
          cnt_played += 1;
        }
        if(score_new == winNum)
        {
          cnt_won += 1;
        }
        scores[cnt_score - 1] = score_new;
        score_old = score_new;
        cnt_score += 1;
      }
    }while(score_new != -1 || score_new != 25);
    results(cnt_score,scores,cnt_won,cnt_played);
return 0;
}

......

void results(int cnt_score,int scores[25],int cnt_won,int cnt_played)
{
  //Local Declarations
    int cnt_loop; //The counter for the for loop

  //Executeable Statements
    printf("\nScores entered (%d): {",cnt_score);
    for (cnt_loop = 1;cnt_loop < cnt_score;cnt_loop++)
    {
      printf("%d, ",scores[cnt_loop - 1]);
    }
    printf("%d}\n",scores[cnt_score - 1]);
    printf("\nNumber of games won: %d\nNumber of games played: %d\n",cnt_won,cnt_played);
}

The errors I am getting are as follows:

hw06.c: In function 'main':
hw06.c:62: warning: passing argument 2 of 'results' makes integer from pointer without a cast
hw06.c:29: note: expected 'int' but argument is of type 'int *'
hw06.c: At top level:
hw06.c:160: error: conflicting types for 'results'
hw06.c:29: note: previous declaration of 'results' was here

3 Answers3

3

Your function prototype doesn't match your function definition:

void results(int,int,int,int);
void results(int cnt_score,int scores[25],int cnt_won,int cnt_played) { ... }

Note that the second parameter is an int *, not an int.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • Isn't the second parameter's type actually `int[25]`? –  Nov 17 '14 at 23:45
  • 1
    @EsaLakaniemi: There's a variety of posts on this: http://stackoverflow.com/a/22677793/47453 – Bill Lynch Nov 17 '14 at 23:51
  • All of those posts i went through with my error seemed to be people forgetting to declare their function, thus it was defaulted as an int. or declaring it as an int then later calling it as a char or something. Couldn't find one where the problem was the parameter being mismatched returning this error. Thanks again for the help though by the way. – Spencer TheCaptain Traylor Nov 17 '14 at 23:58
1

Redeclare the results function as:

void results(int,int[],int,int);
anhlc
  • 13,839
  • 4
  • 33
  • 40
0

The second parameter of your function was declared with type int, but your implementation is of type int[25], an array of integers.

brycem
  • 593
  • 3
  • 9