Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 将二维字符串数组传递给函数?_C_String_Function_Multidimensional Array - Fatal编程技术网

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

C 将二维字符串数组传递给函数?,c,string,function,multidimensional-array,C,String,Function,Multidimensional Array,我正在尝试将此数组发送到函数sortByLength 功能原型是 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 wo

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

功能原型是

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;
}
#包括
#包括“task2.h”
#定义尺寸3
内部主(空)
{
int i;
整数长度[大小]={3,4,6};
字符词[][20]={“太阳”、“雨”、“多云”};
排序长度(单词[][20],长度,大小);
返回0;
}
原型

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

sortByLength(char **words,int * lengths, const int size);  
words[][20]
传递给函数时,将转换为指向
20
char
s数组的指针
char**
char(*)[20]
是不兼容的类型。将功能原型更改为

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

你的问题是什么?为什么不排序长度(单词、长度、大小)@kiks73它不会工作。因为他将其声明为二维数组。但他把它当作指向指针的指针。@Karthikeyan.R.S;它不是指针数组,而是指向指针的指针。@haccks so'char words[][20]'是指向指向第一个元素“Sun”的指针的指针,或者使用
sortByLength(单词、长度、大小)而不是
排序长度(单词[][20],长度,大小)