Hello Everybody I want to attach one String to another. The String that I want to attach is for example: {0x01,0x02,0x03,0x00,0x05} the strcat doesn't copy the bytes after 0x03 because it detects 0x00 as the NUL-Terminator I guess. its the same when I use strncat with the right length parameter. ...but I really need to handle strings like that! Who can help? Thanx a lot
The problem is not with strcat(), it's with your code. You're simply using the wrong tool for the job. strcat() is for strings. And strings, in C, *end* at the first
'\0'
I know the "mem**.." command would be the right one for byte-arrays. The Problem is that they overwrite the 1st array and are not attached. I have 2 arrays (both with a variable and unpredictable length) I wanted to use it for framing where I can put /Header/OptionA[20]/OptionB[5]/OptionC[10]/ but also /Header/OptionC/OptionA/ I think I'll have to do it with counters and construct every concatenation by myself.
If the data in your arrays has no predictable terminator value (like the null character in C strings), then you'll have to remember the length of the data. To concatenate, all you have to do is a bit of pointer arithmetic on your destination.
int memcat (U8* dst, int dstLen, U8* src, int srcLen) { return memcpy (dst + dstlen, src, srcLen); }
typedef struct { ... // various fields here } Header; Header* hdr;
typedef struct { int maxLen; int curLen; U8* data; } BoundedArray;
"The Problem is that they overwrite the 1st array and are not attached." Again, the problem lies in your code - not the library functions! memcpy copies the data you specify to the destination which you specify - so if you specify a destination that will overwrite your 1st array, that's what'll happen! If you don't want it to overwrite your 1st array, then specify the destination address accordingly! This is the You Asked For It, You Got It! (YAFIYGI) programming paradigm! ;-)
Thanx for all that help! The code now does what I want. Have a nice week