This is my first time to use the string function.
And I met some errors while doing the practice.
We now need to input some words, until we input a word with 4 letters.
Then the program will show the smallest and the biggest word among our inputs.
e.g.
Enter the word: dog
Enter the word: zebra
Enter the word: rabbit
Enter the word: cat
Enter the word: fish
Smallest word: cat
Biggest word: zebra
Here is my code. It seems have a fatel error.
#include<stdio.h>
#include<string.h>
#define N 100
void main()
{
char smallest[N]={0L},biggest[N]={0L};
char input[N];
int i,length;
do
{
printf("Enter the word: ");
for (i=0;i<N;i++)
{
scanf("%c",&input[i]);
if (input[i]=='\n')
break;
}
printf("\n\n");
length=strlen(input);
if (strcmp(smallest,input)>=0)
strcpy(smallest,input);
if (strcmp(biggest,input)<0)
strcpy(biggest,input);
}
while (length!=4);
printf("\nThe smallest word is %c",smallest);
printf("\nThe biggest word is %c",biggest);
}
Thanks:)