Hi im trying to access strings stored in 2 different arrays using an array of pointers using the code:
typedef char (*p)[2][20]; //pointer to array of strings ///create dictionaries char names[2][20] = {"jack","john"}; char items[2][20] = {"car"}; p pointer[2]= {&names,&items}; print(pointer[x][y])
replacing x and y with x=1 y=0 prints car, while x=0 y=0 prints jack but im not sure how to print john. using x=0 y=1 prints ( @x, whilst x=1 y=1 also prints jack and x=1 y=2 also prints ( @x. I was wondering how to access john?
pointer[x] is a pointer to an array.
pointer[x]
You need to dereference it to get the array of strings, then index into that.
printf("%s ", (*pointer[x])[y]);
2.1m questions
2.1m answers
60 comments
57.0k users