This sorting routing does not work.
I finally figured out that it probably fails because memory for array is not allocated in one block but in a series of loops that requires array to be addressed as array[j][k]. Am I right?
Code:
void sort ( char ****array, int n, int p, int q) //number of items to sort p, q are rows and columns
{
char temp_page[10][45][12];
int size = 10*45*12;
int j, k;
for(j= (n - 1); j >= 0; j-- )
for(k = 1; k <= j; k++)
if(atoi(array[k - 1][p][q]) > atoi(array[k][p][q]) )
{
memcpy(temp_page,array[k - 1],sizeof(char)*size);
memcpy(array[k - 1],array[k],sizeof(char)*size);
memcpy(array[k],temp_page,sizeof(char)*size);
}
for (j = 0; j < n; j++)
printf("%s \n", array[j][0][3]);
}
I finally figured out that it probably fails because memory for array is not allocated in one block but in a series of loops that requires array to be addressed as array[j][k]. Am I right?