我正在尝试将此数组发送到函数 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/