2*sizeof(float) is the amount in each row of your data
Yes, but the size of each element is sizeof(float*), isn't it? Since each row is a pointer to a float? Anyway, this seemed to work for me.
Here's one way to do it. No guarantees, it's been a while since I used qsort().
Code:
#include <stdio.h>
#include <stdlib.h>
int compare( const void* a, const void* b)
{
float* p1 = *(float**) a;
float* p2 = *(float**) b;
/*printf("Compare %f %x <=> %f %x\n", p1[0], a, p2[0], b);*/
if( p1[1] > p2[1])
{
return -1;
}
else if (p1[1] < p2[1])
{
return 1;
}
else
{
return 0;
}
}
int main()
{
float **array;
int i;
array = (float**)malloc(10*sizeof(float*));
for(i=0; i<10; i++)
{
array[i] = (float*)malloc(2*sizeof(float));
/*printf("[%d] (%x)\n", i, array[i]);*/
}
for(i=0; i<10; i++)
{
/*printf("[%d][%d] (%x), [%d][%d] (%x)\n", i, 0, &array[i][0], i, 1, &array[i][1]);*/
array[i][0] = i;
array[i][1] = 2*i;
}
for( i=0; i<10; i++)
{
printf("%f\t%f\n",array[i][0],array[i][1]);
}
printf("\n\n");
qsort(array, 10, sizeof(float*),compare);
for( i=0; i<10; i++)
{
printf("%f\t%f\n",array[i][0],array[i][1]);
}
return 0;
}