It's because you assign each entry of str_args
to a local pointer, one that goes out of scope once the loop loops.
You might want to consider strdup
:
str_args[i] = strdup(buffer);
Of course, you then have to free
the memory allocated by strdup
.
You also have a problem when printing just after the loop, when you want to print a string, but *str_args[0]
dereferences the first string. i.e. it's the first character and not a string. Remove the dereferencing operator *
and it should work just fine.