title: C array sorting using qsort?
body: <p>I have been stuck on this for a while and nothing seems to work. </p>
  
  <p>I have a data structure:</p>
  
  <pre><code>DATA
  {
    int size;
    int id;
  }
  </code></pre>
  
  <p>And I have an array of DATA structures:</p>
  
  <pre><code>myArray = (DATA *) malloc(10 * sizeof(DATA));
  </code></pre>
  
  <p>Then I assign some test values:</p>
  
  <pre><code>myArray[0].size = 5;
  myArray[1].size = 9;
  myArray[2].size = 1;
  myArray[3].size = 3;
  </code></pre>
  
  <p>So my starting array should look like:</p>
  
  <pre><code>5,9,1,3,0,0,0,0,0,0
  </code></pre>
  
  <p>Then, I call <code>qsort(myArray,10,sizeof(DATA),comp)</code></p>
  
  <p>Where comp is:</p>
  
  <pre><code>  int comp(const DATA * a, const DATA * b)
  {
      return a.size - b.size;
  }
  </code></pre>
  
  <p>And trust me, I tried many things with the compare function, NOTHING seems to work. I just never get any sorting that makes any sense. </p>