B
Boris Gambon
Hi,
After reading tutorials, it's unclear to me how I can create and use
an array of pointers to an existing array of chars.
There is one big row of chars (array of chars) and I want to
dynamically allocate memory for pointers to various places in this row
of chars.
After doing that, I want to be able to use these pointers like this p
[1], p[2] for locations inside the row of chars, starting at the first
char. That should enable code like this: printf("%s", p[1]); or memcmp
in case it's not a string.
example
char data[]="text1\0another-text2\0more-text3\0"; // existing array of
chars, automatically declared
p[0] should point to position 0
p[1] should point to position 6
p[2] should point to position 20
et cetera
Questions:
How to declare a variable for the pointers?
How to malloc memory for the pointers themselves, array of pointers?
How to assign the right position to the pointers?
How to free the allocated array of pointers?
Thanks
Boris
After reading tutorials, it's unclear to me how I can create and use
an array of pointers to an existing array of chars.
There is one big row of chars (array of chars) and I want to
dynamically allocate memory for pointers to various places in this row
of chars.
After doing that, I want to be able to use these pointers like this p
[1], p[2] for locations inside the row of chars, starting at the first
char. That should enable code like this: printf("%s", p[1]); or memcmp
in case it's not a string.
example
char data[]="text1\0another-text2\0more-text3\0"; // existing array of
chars, automatically declared
p[0] should point to position 0
p[1] should point to position 6
p[2] should point to position 20
et cetera
Questions:
How to declare a variable for the pointers?
How to malloc memory for the pointers themselves, array of pointers?
How to assign the right position to the pointers?
How to free the allocated array of pointers?
Thanks
Boris