byte array concatenation

Hi,

I've got two byte array and I want to concatenate them in one. How do I do?

memcpy() could be used to copy the data from one array to the end of the other. Assuming, of course, that there is actually room in the second array to hold the first.

But the better question would be, why? Why do you want to do that? In most situations there's no need for that. A typical XY-problem.

Vincrichaud:
Hi,

I've got two byte array and I want to concatenate them in one. How do I do?

You may not have to. You might simply write whatever you filled the second array with, into an offset of the first array instead. It depends whether your program is using the extra bytes in the first array (which are required as explained above) prior to the memcpy operation. If not, then the memcpy is redundant and you should just be placing the data in the same locations you would have copied to.

Edit - thus, yes, why?

There is string concatenation with chars using strcat(), but the whole idea and benefit of that, is that it is not necessary to keep track of string lengths, as they are encoded with embedded end markers. If you don't have those then you must have pointers or indices to the array in your program, that you can use to locate the byte strings where they belong.