#include <stdio.h>
#include <strings.h>
int main() {
char sentence[100], smallest[100], largest[100];
char words[10][100];
char empty [100] = {'\0'};
printf("Enter a sentence: ");
gets(sentence);
strlwr(sentence);
strcat(sentence, " ");
char tmp[100];
int i = 0, wordcount = 0;
while(sentence[i] != '\0') {
if (sentence[i] == ' ') {
strcpy(words[wordcount], tmp);
wordcount++;
strcpy(tmp, empty);
i++;
continue;
}
tmp[strlen(tmp)] = sentence[i];
tmp[strlen(tmp) + 1] = '\0';
i++;
}
strcpy(smallest, words[0]);
strcpy(largest, words[0]);
for(i=0; i < wordcount; i++) {
if (strlen(smallest) > strlen(words[i]))
strcpy(smallest, words[i]);
if (strlen(largest) < strlen(words[i]))
strcpy(largest, words[i]);
}
printf("Smallest word is: %s\nLargest word is: %s", smallest, largest);
return 0;
}