冲突的类型,当它们都为空时

标签 c

我的代码出现以下错误,其中一个我找不到修复方法。我理解函数类型的声明必须与定义匹配,但确实如此。

#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);
}

我得到的错误如下:

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

最佳答案

您的函数原型(prototype)与您的函数定义不匹配:

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

请注意,第二个参数是一个int *,而不是一个int

关于冲突的类型,当它们都为空时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26983948/

相关文章:

c++ - 在给定数组中找到长度为 k 的所有连续子数组的总和

c - 嵌入式RTOS停止系统

c - 指向结构的指针

c - 通过 udp/snmp 可以发送多少个字符有限制吗?

c - 将指针复制到结构时出现 memcpy 问题

c - 与gcc中的共享库链接时如何为可执行文件生成位置相关代码?

c - 如何获取字符串中的每个字符?

c - 递归增量器

在共享库中调用函数但不在头文件中声明

c - 水库采样算法不起作用