I have a program
#include <stdio.h>
int main()
{
int i , j;
char *str[2][3] = {{"john", "alice", "bobby"},
{"peter", "mark", "anthony"}};
char (*ptr)[3] = str; //Compiler throws Warning here
for ( i = 0 ; i < 2 ; i++)
{
for ( j = 0 ; j < 3; j++)
{
printf("%s ", str[i][j]); //This works fine.
printf("%s ", ptr[i][j]); //segmentation fault here
}
}
}
My intension is to use a pointer to a two dimensional array of pointers. However the compiler throws error as follows;
test.c: In function ‘main’:
test.c:7:19: warning: initialization from incompatible pointer type [enabled by default]
char (*ptr)[3] = str;
^
Also, I am getting segmentation fault while running. My question is how would I have a pointer which points to a two dimensional array of pointers?
*[2][3]?