[英]Conflicting types, when they are both void
我的代码出现以下错误,其中一个找不到解决方法。 我了解函数类型的声明必须与定义匹配,但是可以。
#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
您的函数原型与您的函数定义不匹配:
void results(int,int,int,int);
void results(int cnt_score,int scores[25],int cnt_won,int cnt_played) { ... }
请注意,第二个参数是int *
,而不是int
。
将结果函数重新声明为:
void results(int,int[],int,int);
函数的第二个参数声明为int
类型,但实现的类型为int[25]
(整数数组)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.