copying 2 arrays into one array

Hi,

I have the following requirement.

I have a array b[]= "MP 2 ";

I have a array location[]= "X +1.2345" and location1[]= "Y +3.4567".

Now , I have to append location[] and location1[] to b[] such that my final b[] has the following form b[] = "MP 2 X +1.2345 Y +3.4567\0\r" ..

How do I do this? Any idea?


Thanks
Switch to Ruby, and then just add the arrays.

-Albatross

P.S.- Just kidding. First, get the length of your "MP 2 " string, and the length of your " X +1.2345" string. Then, plug everything into a for loop that copies character-wise those arrays into b[]. Hope you understood that. I omitted some details and steps to force you to think a bit.
Last edited on
Thanks for reply. But I have very less time to think. But this was useful. Thanks
You can use strings instead of arrays:
http://www.cplusplus.com/reference/string/string/
1
2
string b = "MP 2 ", location = "X +1.2345", location1 = "Y +3.4567";
b += location + location1;

or use cstring functions:
http://www.cplusplus.com/reference/clibrary/cstring/strcat/
http://www.cplusplus.com/reference/clibrary/cstring/strncat/
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
Topic archived. No new replies allowed.