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;
}
I'm trying to pass char and char pointer array to a function, but the above code results in the following errors and warnings:
temp.c: In function ‘main’: temp.c:6:5: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration] temp.c:6:13: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default] temp.c:10:5: warning: implicit declaration of function ‘test’ [-Wimplicit-function-declaration] temp.c: At top level: temp.c:15:5: error: conflicting types for ‘test’ temp.c:15:1: note: an argument type that has a default promotion can’t match an empty parameter name list declaration temp.c:10:5: note: previous implicit declaration of ‘test’ was here temp.c: In function ‘test’: temp.c:16:5: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
I'm trying to understand what the problem is.
s1
is just a single character. the prototype oftest
should beint test(char* s1, char **s2)
– eckes-Wall --Werror
). It would catch the bug in this case. – ugoren