title: Sorting alphabetically in C using strcmp
body: <p>I am trying to sort records (structs) by their names. And  I'm using strcmp to swap to detect the alphabetical order. The swapping works fine, however it doesn't always sort the entire list. It always leaves some records in thier incorrect alphabetic order.</p>
  
  <pre><code>void sort_by_name(){
      printf("%d\n", counter);
  
      int i=0, j=0;
      patient *temp;
  
      for(;j&lt;=counter;j++){
          for(;i&lt;counter-1;i++){
  
              if(strcmp(pRecords[i]-&gt;name, pRecords[i+1]-&gt;name) &gt; 0){
  
                  temp = pRecords[i];
                  pRecords[i] = pRecords[i+1];
                  pRecords[i+1]=temp;
  
              }//if loops
  
          }//2nd for loop
  
      }//1st for loop
  
  }
  
  
  counter-- number of records in the system.
  </code></pre>