0
How to combine arrays in c++?
There are two character arrays, for example a{'a','b','c'} and b{'d','e','f'}, you need to get an array c{'a','b','c','d','e','f'} ,how can I do this?
5 Respostas
+ 4
#include <iostream>
#include <cstring>
using namespace std;
#define SIZE 100
int main() {
char a[SIZE] = {'a','b','c'};
char b[SIZE] = {'d','e','f'};
char c[SIZE] = {};
size_t i;
for(i=0; i<strlen(a); i++) c[i] = a[i];
for(i=0; i<strlen(b); i++) c[i + strlen(a)] = b[i];
cout << c << endl;
return 0;
}
// Keep learning & happy coding :D
+ 2
SoloProg good solution.
Alternative way using C string functions:
strcpy(c, a);
strcat(c, b);
cout << c << endl;
+ 1
Pranshu Sachan ,
I don't know about your code show me your code in a correct way.
+ 1
👍👍
0
SoloProg i think size(c) >=size(a) +size(b).
If we want to accumulate all value of a and b into c