title: Struct array's first element become nill after sorting
body: <p>I write code to read student name and their CGPA from a text file and save them in an array of type structure and then sort them in ascending order according to the CGPA. After sorting array’s first element is blank, why?</p>
  
  <p>Structure for type student</p>
  
  <pre><code>struct student{
        char name[20];
        float cgpa;
  };
  </code></pre>
  
  <p>Code to read file</p>
  
  <pre><code>while(!inFile.eof()){    
     inFile&gt;&gt;students[i].name &gt;&gt; students[i].cgpa;  
     cout &lt;&lt; i &lt;&lt; "\t" &lt;&lt; students[i].name &lt;&lt; "\t\t" &lt;&lt; students[i].cgpa &lt;&lt; endl;
     i++;  
  } 
  </code></pre>
  
  <p>Swap function for sorting array content in ascending order according to the CGPA.</p>
  
  <pre><code>void swap(student studentsRcrd[]){
   student tempValue;
    for(int i=0; i&lt;10; i++){      
        for(int j=0; j&lt;10; j++){
           if(studentsRcrd[j].cgpa &gt; studentsRcrd[j+1].cgpa){
                  tempValue = studentsRcrd[j];
                  studentsRcrd[j] = studentsRcrd[j+1] ;
                  studentsRcrd[j+1] = tempValue;
           }
        }
    }
  }
  </code></pre>
  
  <p>Final output on command prompt</p>
  
  <pre><code>No      Name            CGPA
  0       ▄               0
  1       Maria           2.4
  2       Humza           2.6
  3       Saira           2.6
  4       Anila           3
  5       Junaid          3
  6       Usman           3.4
  7       Aasim           3.5
  8       Talaal          3.8
  9       Haris           3.9
  10      Ahmer           4
  </code></pre>