I want to use an array of char pointers where each pointer in the array is pointing to a char in another char array, therefore, I would be able to print the char array through the pointers.
char city[14] = {'D', 'u', 'b', 'a', 'i'};
char *charPointers[100] = {0};
for(size_t i = 0;city[i] != '\0'; i++)
charPointers[i] = &city[i];
printf("\ncity = ");
for(size_t i = 0; *charPointers != 0; i++)
//printf("%c", *(charPointers[i]));
putchar(*charPointers[i]);
Is charPointers an array of pointers or simply a string ?
If it's a string, then how can I use an array of pointers such that each pointer is pointing to a char?
What's an elegant way to achieve what I want? (preferably using pointer arithmetic)
charPointersis an array of pointers; it is not a string. Your second part of the question is moot. You ask "What's an elegant way to achieve what I want" without explaining what you do want.citystring. As I diagnosed in my answer, your printing loop has a flawed terminating condition. You should really be showing, or describing, the output you get. You probably get the city name followed by garbage and eventually a crash, but it would be better if you said that. My answer shows how to fix the problem in plausible ways. What more do you want?