Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: C  |  size: 1.04 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int main(){
  6.  
  7. int number;
  8.  
  9. printf("Input the number of words you want to enter: ");
  10. scanf("%d", &number);
  11.  
  12. if(number<=0){
  13.     printf("You have entered an invalid number.\n");
  14.         do{
  15.         printf("Input the number of strings you want to enter: ");
  16.         scanf("%d", &number);
  17.         }while(number<=0);
  18. }
  19.  
  20. int acounter;
  21. char word[number][100];
  22.  
  23. printf("Input the words:\n");
  24. for(acounter=0; acounter<number+1; acounter++){
  25.     fgets(word[acounter], 99, stdin);
  26. }
  27.  
  28. int bcounter;
  29. char temporary[100];
  30.  
  31. for(acounter=0; acounter<number; acounter+1){
  32.     for(bcounter=0; bcounter<number+1; bcounter++){
  33.         if(strcmp(word[bcounter],word[bcounter+1])>0){
  34.             strcpy(temporary[100], word[bcounter]);
  35.             strcpy(word[bcounter], word[bcounter+1]);
  36.             strcpy(word[bcounter+1], temporary[100]);
  37.         }
  38.     }
  39. }
  40.  
  41. printf("The arranged words are:\n");
  42. for(acounter=0; acounter<number+1; acounter++){
  43.         printf("%s", word[acounter]);
  44.     }
  45.  
  46.  
  47. return 0;
  48. }