Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void sort(char *wilst[], int size){
- for(int i=0; i<size-1; i++){
- if( strcmp (wilst[i], wilst[i+1] ) <0) {
- wilst[i] = wilst[i+1];
- }else{
- wilst[i+1] = wilst[i];
- }
- }
- }
- int main(){
- char word[100];
- int numWords=0;
- char * word_list[100];
- while(scanf("%s", word)!=EOF){
- word_list[numWords] = (char *)malloc(strlen(word)+1);
- strcpy(word_list[numWords],word);
- numWords++;
- if(numWords>=100)
- break;
- }
- sort(word_list, numWords);
- for(int j=0; j<numWords; j++){
- printf("%s\n", word_list[j]);
- }
- for(int n=0; n<numWords; n++){
- free(word_list[n]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment