# qsort problem.

• 11-15-2011
witt
qsort problem.
Hello,

I have a problem with qsort. I let my program generate 50x40 arrays and after i used qsort. The result is not 50x40 anymore. It become a

here is my code
Code:

```#include <iostream> #include <ctime> #include <cstdlib> #include <iomanip> using namespace std; int compare (const void * a, const void * b) {   return ( *(int*)a - *(int*)b ); }   int main() {     const int row=50;     const int column=40;     int table[row][column];     int rnum;     int t[row];       srand(time(0));     rnum = (rand() % 100) + 1;     for(int r=0; r<row; r++)//row     {         for(int c=0; c<column; c++)             table [r][c] = (rand()%100) + 1;     }       for(int r=0; r<row; r++)//row     {         for(int c=0; c<column; c++) //column           {             cout << setw(3) << table[r][c] << ' '; //display table           }         cout << endl;     }       qsort(table, 50 * 40, sizeof(int), compare);       cout << "your new sorted table is: \n";     for(int n=0; n<row; n++)//row     {         for(int m=0; m<column; m++) //column           {             cout << setw(3) << table[n][m] << ' '; //display table           }     }                     system("pause");         return 0;   }```
• 11-15-2011
laserlight
Quote:

Originally Posted by witt
I have a problem with qsort.

Is there any reason why you don't use std::sort?
• 11-15-2011
witt
well I dont even know how to use it or even what it meant sorry
• 11-15-2011
witt
std::qsort(table, 5 * 4, sizeof(int), compare); like this?
• 11-15-2011
witt
well it still not working
• 11-15-2011
iMalc
Since this is C++, forget about qsort. In C++ we use std::sort.
However, regardless of what you use, you have to understand and convey to us, what it means to be sorting a 2D array.

And no sorting cannot change the dimensions of an array. Your assumption that this is happening is wrong.
• 11-17-2011
CodeMonkey
You can sort each row, and then sort the columns... or you can define some ordering (zig-zag) and sort it that way. What are you trying to do?