【发布时间】:2017-07-06 05:52:02
【问题描述】:
我的编译器说“函数中的参数太少”。我不知道出了什么问题。有人知道我做错了什么吗?
#include<stdio.h>
#include<math.h>
int show(int a, int b, int c);
main( ){
int a, b = 10, c = 24;
printf("Enter a number\n");
scanf("%d\n", &a);
show(int a, int b, int c);
system("pause");
}
int show(int a, int b, int c){
if(a>c){
printf("a is the largest number\n");
} else if(a>b){
printf("a is smaller than c\n");
} else if(a<b){
printf("a is bigger than b\n");
} else{
printf("a is the smallest number \n");
}
return;
}
【问题讨论】:
-
show(int a, int b, int c);里面的主到show(a,b,c); -
代码中没有使用来自
<math.h>的任何东西,所以你不需要包含它;你确实使用了<stdlib.h>中的一个函数,所以你需要包含它。您应该在main()上使用显式返回类型——这是自 C99 以来所必需的。您在main()中的show(int a, int b, int c);声明使用了C99 特性——在代码中的任何位置声明——但不包括显式返回类型,但C99 要求这样做。该代码还有很多不足之处。而且您需要在编译器和/或更新的编译器上使用更多警告选项。 -
要跟进@JonathanLeffler 提到的内容,
main()不再是有效的签名,您至少应该使用int main(void)。 -
@JonathanLeffler 对,但是only
main()几乎是无效的,对吗? -
具有显式
int返回类型的函数也不能有return ;,如果它完全有效,这会调用定义不明确的行为。总的来说,这段代码有许多非常基本的问题。我会考虑获取学习 C 的新资源,您当前的资源显然没有帮助。
标签: c