Sorting a two-dimensional array of doubles in C
<p>I'm trying to sort with qsort a two-dimensional array in C.</p>

<p>I have this array: </p>

<pre><code>{ {1.0, 0.0}, {123.0, 1.0}, {2.0, 2.0} }
</code></pre>

<p>and I want it to be sorted by the second value like that:</p>

<pre><code>{ {1.0, 0.0}, {2.0, 2.0}, {123.0, 1.0} }
</code></pre>

<p>I've tried to write an array comparator for qsort but I always get the wrong order of elements.</p>

<p>This is the comparator I wrote:</p>

<pre><code>int CompareArrays(const void* arr1, const void* arr2) {

 const double* one = (const double*) arr1;
 const double* two = (const double*) arr2;
 printf ("one[0] = %lf , one[1] = %lf \n", one[0], one[1]);
 printf ("two[0] = %lf , two[1] = %lf \n", two[0], two[1]);
 if (one[0] &lt; two[0]) return -1;
 if (one[0] &gt; two[0]) return 1;

 return 0;
} 
</code></pre>

<p>I also tried to print the values in order to understand what items are being compared each time, but it keeps printing 0.0000... every time.</p>

<p>Does anyone know what I'm doing wrong? </p>