title: Sorting a list of Strings in Alphabetical order (C)
body: <p>Ok, here is my problem. A teacher has to randomly select a student (from the students she has) to earn a special bonus in the final score and in order to do that she puts N pieces of paper numbered from 1 to N in a bag and randomly select a number K; the award-winning student was the K-th student in the student list. The problem is that the teacher does not know which number corresponds to which student because she lost the paper that contained this information. What she knows: the names of all students, and that, their numbers, from 1 to N, are assigned according to the alphabetical order. </p>
  
  <p>So I need to get the set of names that is given as input, sort them alphabetically and then provide the name of the student who won the special bonus, but I'm having trouble doing so. The program I wrote orders all the names except the first. </p>
  
  <p>In addition, the following warnings appear when I run the project with Code::Blocks: </p>
  
  <ul>
  <li>(line 16) ISO C90 forbids array variable length 's' [-Wvla] </li>
  <li>(Line 13) ISO C90 forbids mixed declarations and code [-Wpedantic]</li>
  </ul>
  
  <p>Please, tell me what am I doing wrong here and if there's a better way to sort the names without having the specified amount of names. </p>
  
  <p>Note: the program should stop reading the input when N and K are equal to zero.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  int main()
  {
      int n, k, i, j=0, aux, numMenorNome;
      char str[]="zzzzzzzzzzzzzzzzzzzz", str2[]="zwyxzzzzzzzzzzzzzzzz";
  
      do
      {
         scanf("%d%d", &amp;n, &amp;k);
         struct student
         {
             char nome[21]; /*name*/
             char nomes_ordenados[21]; /*array to put the names already sorted*/
         } s[n];
  
         for (i=0; i&lt;n; i++)
         {
             scanf(" %s", s[i].nome);
         }
  
         for (i=0; i&lt;n; i++)
         {
             aux = strcmp(str, s[i].nome); /*compares the string that would be the last in the alphabetical order ("zzzzzzzzzzzzzzzzzzzz") with the given names*/
             if(aux&gt;0)
             {
                 strcpy(str, s[i].nome); /*it gives me the name that comes first in alphabetical order */
                 numMenorNome = i;  /* identification number of the name that was obtained */
             }
             if (i==(n-1))
             {
                 strcpy(s[j].nomes_ordenados,str); 
                 printf("%s\n", s[j].nomes_ordenados);
                 strcpy(str, "zzzzzzzzzzzzzzzzzzzz"); 
                 strcpy(s[numMenorNome].nome, str2); 
                 j++;
                 i=0; /* restarts the loop in order to obtain the second name in alphabetical order, the third name, the fourth name and so on */
                 if(j==n)
                      break;
             }
         }
         printf("%s\n\n", s[k-1].nomes_ordenados);
  
      } while (n!=0&amp;&amp;k!=0);
      return 0;
  }
  </code></pre>