C语言 C中的“函数参数太多”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4601193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"too many arguments to function" in C
提问by why
I define a function
我定义了一个函数
int find(char *t, int len){
}
then i call it with
然后我用
value = "hello world";
rt = find(value, strlen(value));
it does not work, and show "error: too many arguments to function ‘find'"
它不起作用,并显示“错误:函数'find'的参数太多”
回答by Vikram.exe
int find(char *t, int len){
}
might give a warning that function should return a value.
可能会警告函数应该返回一个值。
and if you add:
如果你添加:
char* value = "hello world";
int rt = find(value, strlen(value));
It should work fine if the code is in a single file (as already pointed by Michael in comments) else you will have to specify the prototype of findfunction before calling it from a separate file.
如果代码在单个文件中(正如 Michael 在评论中指出的那样),它应该可以正常工作,否则您必须find在从单独的文件中调用它之前指定函数的原型。
回答by iamnagaky
This error might occur when there is difference in argumentsbetween function declaration and function definition.
当函数声明和函数定义之间的参数存在差异时,可能会发生此错误。
回答by Usman
There are two errors that I found in the above code .
我在上面的代码中发现了两个错误。
You have to mention the 'return' keyword at the end of the function definition .
您必须在函数定义的末尾提及 'return' 关键字。
You have to declare the character pointer (char * value) while initialize the 'value' .
您必须在初始化 'value' 时声明字符指针(char * value)。
回答by milkypostman
There is a syntax error in your call, no
;aftervalue = "hello world"Did you
#include <string.h>?
您的调用中有语法错误,没有
;之后value = "hello world"你有
#include <string.h>吗?

