I've been trying to assign char words[x][y] to a char* pointer[x]. But compiler is giving me a error
array type 'char *[5]' is not assignable pointer = &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;
}
But the code works while
char *pointer[5]={"Apple", "Ball", "Cat", "Dog", "Elephant"};
char **dp;
dp = &pointer[0];
all I need is to correctly assign the 2D array into pointer array!!