Hi all,
I have to make a function which take as parameter two arrays and merge in one new.

For example
int array1[][] = {{1 , 2, 3, 4}, {2, 3, 4, 5}};
int array2[][] = {{5 , 6, 7, 8}, {6, 7, 8, 9}};

To take as result
arraynew[][] = {{1 , 2, 3, 4}, {2, 3, 4, 5},{5 , 6, 7, 8}, {6, 7, 8, 9};

Array1 and array2 have 4 columns but the can have more than 2 rows.


Could you help me ???
Please

assuming you got column size compatibility between arrays, you must create an array with x quantity of rows, x being the sum of array1's rows and array's 2 rows (I assume you know these sizes, since you had to declare the arrays sizes). After that, you create two nester for loops to go through both arrays one after another. This way:

int sizex = 4, sizey1 = 2; sizey2 = 3;
int array1[sizex][sizey1]={{1,2,3,4},{2,3,4,5}};
int array2[sizex][sizey2]={{3,4,5,6},{4,5,6,7},{5,6,7,8}};
int array3[sizex][sizey1+sizey2];

for (int x = 0 ; x < sizex ; x+=1)
{
   for (int y = 0 ; y < sizey1 ; y+=1)
   {
      array3[x][y] = array1[x][y];
   }
}
for (int x = 0 ; x < sizex ; x+=1)
{
   for (int y = sizey1 ; y < sizey2 ; y+=1)
   {
      array3[x][y] = array1[x][y];
   }
}

this way, array3 would be:

{1,2,3,4}
{2,3,4,5}
{3,4,5,6}
{4,5,6,7}
{5,6,7,8}

commented: Giving away homework still? You really know better. -2

Thanks a lot !

remember marking solved threads as solved ;)

commented: Maybe you should share your bath with a toaster, then you won't have to beg for solved threads anymore. -1
commented: why? you keeping score? what makes youi think your sloppy snippet is worth a "solved" anyhow? -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.