Charles L <tj***@dodo.com.au> wrote:
I would like to know how to convert an array of characters generated from a
previous operation to a string ie how do I append a null character at the
end? I haven't been able to do it so far. Is there a string function I can
use?
Do you track how many characters you have?
If you know this, what you want to do is easy.
long nCharacters; /*should be set to the number of characters you*/
/*have*/
yourString[nCharacters] = '\0';
This does assume 'yourString' has the space to store the null character.
If you do not know that it does, you will need to dynamically allocate a
string that will.
long nCharacters; /*should be set to the number of characters you*/
/*have*/
char *newString = NULL;
newString = malloc( nCharacters + 1 ); /*should check for NULL*/
strncpy( newString, yourString, nCharacters );
newString[nCharacters] = '\0';
If you do not know how many characters you have or cannot determine it,
what you want to do is impossible.
--
== Eric Gorr =========
http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===