typedef struct {
char * array[10];
} List;
int main(void) {
List input;
input.array = (char **)malloc(10 * sizeof(char));
if (input.array == NULL)
exit(EXIT_FAILURE);
for (i = 0; i < 10; i++) {
input.array[i] = (char *)malloc(10 * sizeof(char));
if (input.array[i] == NULL)
exit(EXIT_FAILURE);
}
}
我正在尝试初始化一个由 10 个字符指针组成的数组,每个指针指向一个长度为 10 的不同字符串。
我从 gcc 收到以下错误:
incompatible types when assigning to type ‘char *[10]’ from type ‘char **’
我对 malloc 的调用一定不正确,但怎么会这样呢?