title: sorting 2-d array based on the first column
body: <p>I have a <code>temp2.dat</code> file that looks like this:</p>
  
  <pre><code>0.060493 1 0.5 1
  1.596961 0 0.1 2
  0.87758  1 0.3 1.5
  0.165453 1 0   3
  0.07085  1 0.3 4
  0.125379 1 0.2 3
  0.454202 1 0.2 2
  0.373227 1 0.3 1
  0.131486 1 0.3 3
  0.867477 0 0.5 4
  0.122609 0 0.8 9
  </code></pre>
  
  <p>Now I want to write the function in <code>C</code> to sort these 4 columns in an increasing order but only based on the values of the first column. I tried modifying the following code but it failed:</p>
  
  <pre><code>struct data_t
  {
      double x;
      int y;
      double z;
      double k;
  };
  
  int compare(const void *a, const void *b)
  {
      const struct data_t *m = a;
      const struct data_t *n = b;
      if(m-&gt;x == n-&gt;x)
          return m-&gt;y &gt; n-&gt;y;
          return m-&gt;z &gt; n-&gt;z;
          return m-&gt;k &gt; n-&gt;k;
      return m-&gt;x &gt; n-&gt;x;
  }
  </code></pre>
  
  <p>Could someone please help me do this? The expected result should look like this:</p>
  
  <pre><code>0.060493 1 0.5 1
  0.07085  1 0.3 4
  0.122609 0 0.8 9
  0.125379 1 0.2 3
  0.131486 1 0.3 3
  ................
  0.87758  1 0.3 1.5
  1.596961 0 0.1 2
  </code></pre>