我一直在尝试将 char words[x][y] 分配给 char* pointer[x]。但是编译器给了我一个错误
数组类型 'char *[5]' 不可分配 指针 = &words[0]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
char words[5][10]={"Apple", "Ball", "Cat", "Dog", "Elephant"};
char *pointer[5];
pointer = &words[0];
char **dp;
dp = &pointer[0];
int n;
for(n=0; n<5; n++){
printf("%s\n", *(dp+n));
}
return 0;
}
但是代码有效
char *pointer[5]={"Apple", "Ball", "Cat", "Dog", "Elephant"};
char **dp;
dp = &pointer[0];
我所需要的只是将二维数组正确分配到指针数组中!!