copy strings in array

This is a discussion on copy strings in array within the C Programming forums, part of the General Programming Boards category; hi,
i have a string printed to by sprintf. i would like to: for every string printed, it copies the ...

As you have been told, sa is an array of pointers, which are uninitialized. Pointers are not a storage unit.
And trying to print the contents from an uninitialized pointer will undoubtedly cause a crash right away.http://cpwiki.sourceforge.net/Common...kes_and_errors

for every string printed, it copies the contents into the next element of a char array:

means. By definition, you cannot get a string into the next element of a char array -- the only thing you can get into the next element of a char array is a char.

Now, since you don't have any char arrays in your code, but do have char * arrays, I assume you mean that. In that case, sa[0], sa[1], ... are already your char *s that you would want to copy to, so adding & is fruitless. HOWEVER: currently sa[0], sa[1], etc. point to somewhere in New Jersey. You need to make them point to a string inside your computer, usually using malloc.

Yes, or just make them allocated on the stack.
There are several ways to assign values to arrays, depending on what you need.
If you need string literals (non-modifiable), assign a string literal to a const char* pointer.
If you need a modifiable buffer, then create a buffer and use strcpy.