title: sort word in alphabet order in C
body: <p>Below code is for a test sample given in <a href="https://www.testdome.com/for-developers/solve-question/9621" rel="nofollow noreferrer">https://www.testdome.com/for-developers/solve-question/9621</a></p>
  
  <p>The question is: 
  Implement function sort_words that can sort an array of words which contain lowercase characters from english alphabet, in descending order.</p>
  
  <p>For example, the array { "cherry", "orange", "apple" } should, after sorting, become { "orange", "cherry", "apple" }.</p>
  
  <p>My code is:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
  void sort_words(char *words[], int count)
  {
      char *x;
  
      for (int i = 0; i&lt;count; i++)
      {
          for (int j = i + 1; j&lt;count; j++)
          {
              if ((char)(*words[i]) &lt; (char)(*words[j]))
              {
                  x = words[j];
                  words[j] = words[i];
                  words[i] = x;
              }
          }
  
      }
  }
  
  #ifndef RunTests
  int main()
  {
      char *words[] = { "cherry", "orange", "apple" };
  
      sort_words(words, 3);
  
      for (int i = 0; i &lt; 3; i++)
      {
          printf("%s ", words[i]);
      }
  }
  #endif
  </code></pre>
  
  <p>Result is correct, but the system notices the fail information "Performance test on a dictionary: Time limit exceeded"</p>
  
  <p>Why this error happens and how to solve this problem? Thanks!</p>