I would like to append a String object to an array of characters.
My code looks something like this;
String msg = "123456"
char charArr[1600];
//assume charArr already contains some string
//How can I do something like this to append String to charArray?
charArr = charArr + msg;
int sizeOf = 6;
int i = 0;
int offset = 0;
char charArr[1600];
String msg = "123456";
while((i<sizeOf) && (charArr[i+offset] != '\0') && (msg[i] != '\0'))
{
charArr[i+offset]=msg[i];
i++;
}
This should technically work since strings are just arrays of chars. If it doesn't, than use msg as an array of chars explicitly. Do you need msg to be of type string specifically?
the real question is why the h*ll do you want to doString msg = "123456";versus char msg[] = "123456"; if you have no good reason to use the String class, just don't...
if you really need to have a String (with a capital S) then the class has a method msg.c_str() that will convert the contents of msg to a C-style, null-terminated char array. so you could just use strcat to concatenate the charArr and the msg.c_str()
(side note 1600 bytes depending on your arduino is a lot of memory)