title: first and last words in alphabetical order in c
body: <p>This is a c prog which takes 5 words separated by spaces and gives the first and last word acc to alphabetical order. eg.Enter 5 words: banana ap pa kiwi orange. first word=ap last word=pa.No error is shown but the prog isn't working, like more than 5 words are being accepted.This is my code:</p>
  
  <pre><code>void findWord(char word[][20], char *first, char *last);
  int main()
  {
      char word[5][20];
      char *first, *last;
  
      printf("Enter 5 words separated by spaces: \n");
      for (int i = 0; i &lt; 5; i++)
      {
          for (int j = 0; j &lt; 20; j++)
              scanf("%c", &amp;word[i][j]);
  
      }
      first = word[0][0];
      last = word[0][0];
  
      findWord(word, &amp;first, &amp;last);
      printf("The first word is: %s and the last word is: %s  ", first, last);
  
  }
  
  void findWord(char word[][20], char *first, char *last)
  {
      int k, l;
  
      for (k = 0; k &lt; 5; k++)
      {
          for (l = 0; l &lt; 20; l++)
          {
              while ((word[k][l] != '\0') &amp;&amp; (word[k][l] == ' '))
              {
                  if (word[k][l + 1]&lt; *first)
                      *first = word[k][l + 1];
                  else 
                      *last = word[k][l + 1];
              }
          }
      }
  }
  </code></pre>