If you do have a 3D array std::string foo[X][Y][Z]; you obviously have N == X*Y*Z elements.
If you have also a 2D array std::string bar[R][S]; // where R*S >= N , then you have room for all elements of foo in it.
Now, the task is to iterate over one array, and copy each element to the other array. For example:
1 2 3 4
size_t i = x*Y*Z + y*Z + z;
size_t r = i / S;
size_t s = i % S;
bar[r][s] = foo[x][y][z];
The more you know about your system, the better you can optimize it.
When you say "3D array contains strings", are you talking about a 3D array of chars (which contains strings in C-style buffers) like I thought you were talking about in this earlier thread of yours:
In this case you should think of the arrays as being 2D and 1D arrays (of char buffers)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// where x, y, z are all const integral values
char myArray[x][y][z];
char myOtherArray[x * y][z]; // target array must be at least x * y
// etc
for ( int i = 0; i < x; i++ )
{
for ( int j = 0; j < y; j++ )
{
// or you could use a running index
strcpy(myOtherArray[i*y + j], myArray[i][j]);
}
}
// etc
I got lost at line 14. You are using strcpy. The is basically the function im trying to recreate.
Can I replace line 14 with this or something similar.