is it possible to add two 2D arrays to create a larger array?

I'm writing a program where certain options from arrays are only available when certain conditions are met.
I'm a bit stuck on one part.

thingy1[10][20] =
"test1 , test2 "

thingy2[10][20] =
"test3 ","test4 "

Is there a way of then turning this into a single array, so I get the following?

thingy1[10][20] =
"test1 ","test2 ", "test3 ", "test4 "

I basically want the second array to be added to the first, so there are more options. I'm going to continue to do this too.
Will a simple strcat(thingy1, thingy2) do?

Thanks in advance
Yes, it is possible only if (number of elements of thingy1 + number of elements of thingy2 is <=thingy1 array size).

So the above result is can be achieved using strcpy while taking care of array indices not to go out of range.
Last edited on
Thanks for the response. How exactly will I be able to use strcpy?
From what I know of it in the following example

strcpy(thingy1, thingy2);

wouldn't it erase thingy1 with thingy2? If it adds thingy2 to thingy1, that's exactly what I need.
This statement

strcpy(thingy1, thingy2);

is incorrect.
Will strcpy work?
Yes, but need more details or examples?
Ok. What I'm basically doing is a adding more to the array if certain conditions are passed.

For example, if strength = 6, then I would add the appropriate array.
I will be doing this repeatedly for each attribute, so the original array will increase in size for each passed check.
If your array has to be increased then it is better to use std::vector<std::string>.
Last edited on
I know, but for the project I'm actually not allowed to use strings for what I am doing, it has to be arrays.


Done some more research on strcpy and I found out how I can do this.

I can strcpy individual parts of the array.
The basic idea is:

I haven't been able to try it yet, but I believe that this is basically what is possible. However, I would have to be able to retrieve what the total number of an array is each time before I use that number to find the first empty location before I add to the original array. Is this possible with a for loop?

int total = 0;
for(int i=0; i<10;i++)
if thingy[i] = "/0"
total = i

and so on?
Last edited on
Topic archived. No new replies allowed.