Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Question1
Language: C/C++
Code:
#include <stdio.h>


int main(){
   int i, j, l, k, count;
   char str[25][25], temp[25];
   count = 0;                                                                         
   char choice;                                                                       
   puts("You can enter a maximum of 25 words");
   puts("Wanna enter (Y/N)? ");
   gets(&choice);
   while(choice == 'Y' || choice == 'y')                                              
   {
       puts("Enter: ");
       gets(&str[count]);
       count++;
       puts("Another word (Y/N)? ");
       gets(&choice);
   }


   for(i = 0; i < count; i++)
   {

      for(j = i + 1; j < count; j++)
      {
        k = 0;
        while((str[i][k] == str[j][k]) && (str[i][k] != '' && str[j][k] != ''))   
            k++;
        if(str[i][k] > str[j][k])
        {
            for(l = 0; str[j][l] != ''; ++l)                                        
                temp[l] = str[j][l];
            temp[l] = '';
            for(l = 0; str[i][l] != ''; ++l)
                str[j][l] = str[i][l];
            str[j][l] = '';
            for(l = 0; temp[l] != ''; ++l)
                str[i][l] = temp[l];
            str[i][l] = '';

        }


      }
   }
   if (count != 0)
   {
        for(i = 0; i < count; i++)                                                   
            puts(str[i]);
   }
   else
   {
       printf("No words entered n");
   }
   getch();
   return 0;
}

          
Comments: