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

Untitled

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