title: How to sort an array of string alphabetically (case sensitive, nonstandard collation)
body: <p>I need a c language code to sort some strings and it should be case sensitive and <strong>for the same letter in upper- and lower-cases, the lower-case must come first</strong>. For example the result of the sort for the following strings:</p>
  
  <pre><code>eggs
  bacon
  cheese
  Milk
  spinach
  potatoes
  milk
  spaghetti
  </code></pre>
  
  <p>should be:</p>
  
  <pre><code>bacon
  cheese
  eggs
  milk
  Milk
  potatoes
  spaghetti
  spinach
  </code></pre>
  
  <p>I have written a code but the result that I am getting is:</p>
  
  <pre><code>Milk
  bacon
  cheese
  eggs
  milk
  potatoes
  spaghetti
  spinach
  </code></pre>
  
  <p>I have no idea how to improve this and I have searched a lot. Could anyone help me with this?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(){
      char c;
      char name[20][10], temp[10];
      int count_name = 0;
      int name_index = 0;
      int i, j;
  
      while ((c = getchar()) != EOF){
          if (c == 10){
              name[count_name][name_index] = '\0';
              count_name++;
              name_index = 0;
          } else {
              name[count_name][name_index] = c;
              name_index++;
          }
      }
  
      for(i=0; i &lt; count_name-1 ; i++){
          for(j=i+1; j&lt; count_name; j++)
          {
              if(strcmp(name[i],name[j]) &gt; 0)
              {
                  strcpy(temp,name[i]);
                  strcpy(name[i],name[j]);
                  strcpy(name[j],temp);
              }
          }
      }
  
      for (i = 0; i &lt; count_name; i++){
          printf("%s\n", name[i]);
      }
  }
  </code></pre>