David Chevalier wrote:
hmmm... i'm now thinking for wide char support you'd need to also multiply the field_len by the Char size...Michel.P wrote:I want to insert a null character at the end of a
couple of strings and then concatenate (pack) them but
I simply don't know how to get it to work.
The way I try to do it now is like this:
//Here his where we'll store the concatenated strings
Char *packed;
//Here's where we want to add the null chars Char *field1, *field2;
.
.
.
//Assume that field1+2 now have values asigned,
WITHOUT null-terminator
//+2 for null chars
packed = MemPtrNew(StrLen(field1) + StrLen(field2) +
2);
//Add 1 - presumably the null
StrNCat(packed, field1, StrLen(field1)+1);
//Here the string should be appended AFTER the null
char
StrCat(packed, field2);
Apparently StrCat() overrites the null char (or so it
seems).
I'm lost, any help would be much appreciated, I've
already spent way too much time on this one...
Are your field1 and 2 strings null-terminated to start with?
(don't call StrLen() on them if they aren't!)
Assuming you want: packed = field1, null, field2, null
then I'd suggest just to write them using MemMove():
// fieldX: unterminated strings
// fieldX_len: length of string X, determined by some means-
// for example, return param from NetLibReceive()
Char null = chrNull;
Char *ptr = packed;
MemMove(ptr, field1, field1_len);
ptr += field1_len;
MemMove(ptr, &null, sizeof(null));
ptr += sizeof(null);
// ... repeat for field 2, etc
If field1 and 2 were null-terminated to start with, no need for the null stuff, just copy one more Char as you did above. You can't use StrCat or StrCopy to get extra nulls in there, anyway.
Of course, you could also simply write each index into the Char array...
-Dave
MemMove(ptr, field1, field1_len * sizeof(Char));
sorry! Its hard for me to remember that sizeof(Char) is not always 1...
--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
