Guest User

Untitled

a guest
May 22nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void sort(char *wilst[], int size){
  6.     for(int i=0; i<size-1; i++){
  7.         if( strcmp (wilst[i], wilst[i+1] ) <0) {
  8.             wilst[i] = wilst[i+1];
  9.         }else{
  10.              wilst[i+1] = wilst[i];
  11.         }
  12.     }
  13.  
  14. }
  15. int main(){
  16.  
  17.     char word[100];
  18.     int numWords=0;
  19.     char * word_list[100];
  20.  
  21.     while(scanf("%s", word)!=EOF){
  22.             word_list[numWords] = (char *)malloc(strlen(word)+1);
  23.                 strcpy(word_list[numWords],word);
  24.                 numWords++;
  25.  
  26.                 if(numWords>=100)
  27.                     break;
  28.    
  29.     }
  30.     sort(word_list, numWords);
  31.     for(int j=0; j<numWords; j++){
  32.         printf("%s\n", word_list[j]);
  33.  
  34.     }
  35.  
  36.     for(int n=0; n<numWords; n++){
  37.         free(word_list[n]);
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment