title: Sorting 2D array according to one column in C programming
body: <p>I started coding about 10 weeks ago and I'm currently stuck doing a 2D array assignment :/</p>
  
  <p>The program is supposed to randomly assign numbers into each column, showing the score of exam1, exam2 and the average score of each student, which is simple.</p>
  
  <p><img src="https://i.stack.imgur.com/zuBWz.png" alt="enter image description here"></p>
  
  <p>But, now I'm supposed to sort the 2D array according to their final "Score."</p>
  
  <p><img src="https://i.stack.imgur.com/kIauM.png" alt="enter image description here"></p>
  
  <p>The professor only taught us how to do a bubble sort with 1D array, but not with 2D array. But, I still tried to improvise somehow.</p>
  
  <p>This is the code I used:</p>
  
  <pre><code>/*for(i = 0; i &lt; 29; i++){
      for(j = 29; j &gt; i; j--)
          if(array2[j-1][4] &lt; array2[j][4]){
                  t = array2[j-1][4];
                  array2[j-1][4] = array2[j][4]; array2[j][4] = t[4];
          }
  }*/
  </code></pre>
  
  <p>But, this would only sort the "Score" column and show the grade for each score, however, not sorting the whole row.</p>
  
  <p><img src="https://i.stack.imgur.com/gL7Hp.png" alt="enter image description here"></p>
  
  <p>So, I tried to move the whole row into a 1D array and then swap.</p>
  
  <pre><code>for(i = 0; i &lt; 29; i++){
      for(j = 29; j &gt; i; j--)
          if(array2[j-1][4] &lt; array2[j][4]){
              for(r = 0; r &lt; 4; r++)
                  t[r] = array2[j-1][r];
              for(r = 0; r &lt; 4; r++)
                  array2[j-1][r] = array2[j][r];
              for(r = 0; r &lt; 4; r++)
                  array2[j][r] = t[r];
          }
  }
  </code></pre>
  
  <p>But the code above wouldn't do anything and the array2 will stay the same :/</p>
  
  <p>Any help?</p>