I have the following code:
int main(){
char **array;
char a[5];
int n = 5;
array = malloc(n *sizeof *array);
/*Some code to assign array values*/
test(a, array);
return 0;
}
int test(char s1, char **s2){
if(strcmp(s1, s2[0]) != 0)
return 1;
return 0;
}
我正试图将char和char指针数组传递给一个函数,但上面的代码导致以下错误和警告:
temp.c:在函数'main'中: temp.c:6:5: 警告:隐式声明函数‘malloc’[-Wimplicit-function-declaration] temp.c:6:13: 警告:不兼容的内置函数‘malloc’的隐式声明[默认情况下启用] temp.c:10:5: 警告:隐式声明函数‘test’[-Wimplicit-function-declaration] temp.c:在顶层: temp.c:15:5: 错误:‘test’的类型冲突 temp.c:15:1: 注意:具有默认提升的参数类型不能匹配空参数名列表声明 temp.c:10:5: 注意:之前的‘test’的隐式声明在这里 temp.c:在函数'test'中: temp.c:16:5: 警告:隐式声明函数‘strcmp’[-Wimplicit-function-declaration]我试图理解问题出在哪里。
s1
只是一个单个字符。test
的原型应该是int test(char* s1, char **s2)
。 - eckes-Wall --Werror
参数,将所有警告视为错误。这样可以在这种情况下捕获错误。 - ugoren