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.
append(char[] str) method appends the string representation of the char array argument to this sequence. The characters of the array argument are appended, in order, to the contents of this sequence. The length of this sequence increases by the length of the argument.
Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.
A C-style string is a null (denoted by \0 ) terminated char array. The null occurs after the last character of the string.
To store the words, a 2-D char array is required. In this 2-D array, each row will contain a word each. Hence the rows will denote the index number of the words and the column number will denote the particular character in that word.
You should have enough space for array1
array and use something like strcat
to contact array1
to array2
:
char array1[BIG_ENOUGH];
char array2[X];
/* ...... */
/* check array bounds */
/* ...... */
strcat(array1, array2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With