for some reason I cannot explain, every single item in the character array...is equal to the last item added to it...for example progArgs[0] through progArgs[size] contains the
You're assigning the same pointer (the address of the first element of the stack array item
) to each element of progArgs
, then repeatedly overwriting that memory. You can do:
progArgs[count] = strdup(t->c_str());
and get rid of the first two lines of the for body.
strdup
allocates memory, so you will have to free each element with free
later. Also, you were not allocating a character for the NUL-terminator. You need would strlen
+ 1. However, this is not an issue with strdup
, since it allocates for you.