[LC++] filling char* arrays

Joaquim Duran Comas jdurancomas at gmail.com
Mon Jun 23 08:37:34 EST 2008


> Hello everone!
>    Thyis is not strictly c++, although it is embedded in c++ code.
>    I want to dynamically fill a char pointer array, how best to go about it?
> The array is one or two elements long, should I just go for:
> char* buttons[2];
> buttons[0] = strdup("Yes");
>    Or what should I do? I have to fill the array depending on an if-
> statement.
>    Thanks in advance for any good, practical tip.
>    Kindest regards
>          Julien

Hello,

Note: By error, I've sent an unfinished replay to Julien message.
Sorry for the inconveniences and send it to the trash.

My suggestion is to use an array of pointers (Like what you do):

char *buttons[] = { "Yes", "No", "Pause", "Stop", NULL};

The compiler will calculate the size of the array.

Thanks and Best Regads,
Joaquim Duran



More information about the tuxCPProgramming mailing list