小编use*_*057的帖子

将char指针数组传递给C中的函数?

我有以下代码:

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;
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试将char和char指针数组传递给函数,但上面的代码会导致以下错误和警告:

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: …

c arrays pointers char

4
推荐指数
1
解决办法
7934
查看次数

标签 统计

arrays ×1

c ×1

char ×1

pointers ×1