"jt" <jt****@hotmail .com> writes:
I can't seem to find a way to concatenate strings that have nulls
within the string.
I have a string that I need another string that has nulls in it and
what to append the 2nd string, 3 string and so forth to the 1st
string.
Any ideas how to go about this?
It's logically impossible. A "string" is, by definition, "a
contiguous sequence of characters terminated by and including the
first null character" (C99 7.1.1p1). If a sequence of characters
includes a null character other than at the end, it's not a string.
Since strcat() works with strings, it can't work with the sequences
you're using (as I'm sure you've discovered.
Since you don't have the trailing '\0' to mark the end of your
sequence, you have to have some other way of specifying how long it
is. Once you've done that, you can probably use memcpy() (or
memmove() if there's a possibility of overlap) to copy things around.
The required arguments to memcpy() are determined by the lengths of
the sequences you want to copy. Since you haven't told us how that's
defined, we can't provide more details.
Of course, you still have the same memory allocation issues (making
sure the target is big enough to hold the concatentated result) that
you have with real strings.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.