Usually the method would be to declare the string to be big enough to hold the largest item expected. The items don't all have to fill the string entirely every time.
Before putting anything into a fixed-length string, make sure that it isn't longer than the string.
char SUP[2] = "km";
Is not a char. It is a char array containing 2 bytes of space. One containing the k, the other containing the m.
Becouse there are only two bytes of space declaired you can not add anything to it. If you want to add to it you should make something like this:
Char SUP[16] = "km";
This places the k in the first byte, the m in the second byte and leaves 14 bytes for you to add data to.
I hope this helps,
Elvenstof
And now the million dollar question, why do you want to? On a micro you rarely need to do that? Because most of the times we just want to output that string somehow. Then simply output the two part right after each other
This thread seems to be full of the common confusion of Strings (objects created using the String library) and C style strings (zero terminated arrays of chars)
Both methods have functions to manipulate the variables but the functions are not generally interchangeable.
The first decision is whether to use Strings or strings. The latter are generally preferred when using an Arduino because they do not lead to memory fragmentation. Having made the decision then suitable variables of the correct type need to be declared. In the case of strings allowance must be made for the terminating zero which takes up one extra byte in the char array over and above the characters, hence my question in reply #3
Once the data is in the variables then the appropriate functions can be used to find the length of a string (or String), the position of characters within it and to concatenate or split them as required. Robin's post #4 has a link to the functions available to manipulate strings.
Some of the code posted in this thread does not compile, even the humble
char SUP[2] = "km";
which I believe exposes some of the confusion.
So, which is it to be Strings (possibly inefficient) or strings (often seen as complicated but in reality not so)
char SUP[2] = "km"; will compile fine. The trailing nul will be "squeezed out" and not included. You can't use it in any functions that count on a trailing '\0', but it might be fine for other purposes.
strncpy(txt, SUP, 2); will not copy the terminating nul character of SUP (assuming SUP is now three characters) and hence you can not use strncat(txt, A, len);
The size of your (lower case) txt variable is also one to small. Count the characters 6 + 2 equals 8 and hence no space for the nul terminator.