
Untitled
By: a guest on
Aug 6th, 2012 | syntax:
C | size: 1.03 KB | hits: 12 | expires: Never
#include<stdio.h>
#include<string.h>
int main(){
int number;
printf("Input the number of words you want to enter: ");
scanf("%d", &number);
if(number<=0){
printf("You have entered an invalid number.\n");
do{
printf("Input the number of strings you want to enter: ");
scanf("%d", &number);
}while(number<=0);
}
int acounter;
char word[number][100];
printf("Input the words:\n");
for(acounter=0; acounter<number+1; acounter++){
fgets(word[acounter], 99, stdin);
}
int bcounter;
char temporary[100];
for(acounter=0; acounter<number; acounter+1){
for(bcounter=0; bcounter<number+1; bcounter++){
if(strcmp(word[bcounter],word[bcounter+1])>0){
strcpy(temporary, word[bcounter]);
strcpy(word[bcounter], word[bcounter+1]);
strcpy(word[bcounter+1], temporary);
}
}
}
printf("The arranged words are:\n");
for(acounter=0; acounter<number+1; acounter++){
printf("%s", word[acounter]);
}
return 0;
}