R
ramu
Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
Regards
Could anyone please tell me how to dereference a pointer to an
array of pointers?
Regards
Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
Regards
/* set up a pointer to a list of pointers, here strings for readability */ramu said:Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
Could anyone please tell me how to dereference a pointer to an
array of pointers?
/* set up a pointer to a list of pointers, here strings for readability */
char **strings;
int i;
strings = malloc(12 * sizeof(char *));
for(i=0;i<12;i++)
{
strings = malloc(32);
sprintf(strings, "string %d", i+1);
}
/* dereference to get a string, or char * */
printf("%s\n", strings[3]);
/* dereference to get a character, should be the letter g */
printf("%c\n", strings[3][5]);
As you can see, when you say "dereference the pointer" you can mean either
get what it points to immediately, which is another pointer, or what it
points to ultimately, which in this case is a char.
*strings is equal to strings[0] and it has nothing to do with 'singleAlso we can use this syntax
/* treat as pointer to single element */
printf("%s\n", *strings);
.... snip ...
Really, i don't undestand your post, OP asked for a pointer to
array of pointers and you answered with a char **?
Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.