Need help with 2-dimensional array

I am trying to send the last x rows of a 2-dimentional array to a function that receives a one-dimensional array and sorts it. Can anyone help me with this? I had an idea to copy the elements of the desired rows of the 2-dimensional array to a one dimensional array and to send that array to the function but it isn't working right.

This is the program I wrote to populate the one dimensional array with the elements of a row but it only populates the last index of the desired row to every index of the one dimensional array:

int MAX_ROWS = 15, FIRST_ROW, one_d_array[30];
FIRST_ROW = MAX_ROWS - size;
for(int i = FIRST_ROW; i < MAX_ROWS; i++)
for(int j = 0; j < 30; j++)
for(int k = 0; k < 30; k++)
one_d_array[k] = arr[i][j];

This is giving me a problem, if for example the last index of the row is 96 when I print the one-dimensional array all 30 indexes are 96.

note: variable "size" is used higher up when I was doing a randomize function. size is the number of rows from the bottom of the 2-dimentional array the user wanted to randomize. That part of my program is working fine. This part that I'm stuck at is taking those same rows the user wanted to randomize and sorting them.





EDIT:
I changed it to this:

int MAX_ROWS = 15, FIRST_ROW, one_d_array[30], k = 0;
FIRST_ROW = MAX_ROWS - size;
for(int i = FIRST_ROW; i < MAX_ROWS; i++)
for(int j = 0; j < 30; j++)
{
one_d_array[k] = arr[i][j];
k++;
}


and it seems to be working. Still would appreciate any insight.
Last edited on
Topic archived. No new replies allowed.