c - 将二维字符串数组传递给函数?

标签 c string function multidimensional-array

我正在尝试将此数组发送到函数 sortByLength

函数原型(prototype)为

sortByLength(char *words[],int * lengths, const int size);

这是我尝试将它传递给函数的其余代码:

#include <stdio.h>
#include "task2.h"
#define SIZE 3

int main(void)
{
    int i;
    int lengths[SIZE] = {3, 4, 6};
    char words[][20] = {"Sun", "Rain", "Cloudy"};

    sortByLength(words[][20],lengths,SIZE);

    return 0;
}

最佳答案

原型(prototype)

sortByLength(char *words[],int * lengths, const int size);  

相当于

sortByLength(char **words,int * lengths, const int size);  

words[][20] 将转换为 指向 20 char 数组的指针一个功能。 char **char (*)[20] 是不兼容的类型。将函数原型(prototype)更改为

sortByLength(char (*words)[20], int *lengths, const int size); 

关于c - 将二维字符串数组传递给函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29225288/

相关文章:

c - 返回数组c函数

c - 为什么我的 printf 不起作用?

javascript - 匹配字符串

python - 在 python 3.x 中声明其主体之前调用函数

scala - A<:< SomeType parameter declaration

javascript - css jquery的函数参数

c - lab_get_obj()中的slab_bufclt()是什么意思?

c - 如何检查点 (x,y) 是否在笛卡尔坐标系中的多边形内?

java - 如何检查字符串是否等于有效字符之一? (棋盘)

c - 更新函数内的字符串数组