Append to the end of a Char array in C++
Posted
by
Taylor Huston
on Stack Overflow
See other posts from Stack Overflow
or by Taylor Huston
Published on 2012-03-31T10:50:25Z
Indexed on
2012/03/31
11:29 UTC
Read the original article
Hit count: 171
Is there a command that can append one array of char onto another? Something that would theoretically work like this:
//array1 has already been set to "The dog jumps "
//array2 has already been set to "over the log"
append(array2,array1);
cout << array1;
//would output "The dog jumps over the log";
This is a pretty easy function to make I would think, I am just surprised there isn't a built in command for it.
*Edit
I should have been more clear, I didn't mean changing the size of the array. If array1 was set to 50 characters, but was only using 10 of them, you would still have 40 characters to work with. I was thinking an automatic command that would essentially do:
//assuming array1 has 10 characters but was declared with 25 and array2 has 5 characters
int i=10;
int z=0;
do{
array1[i] = array2[z];
++i;
++z;
}while(array[z] != '\0');
I am pretty sure that syntax would work, or something similar.
© Stack Overflow or respective owner