#include <stdio.h>
void main()
{
char str[100];
int i,maxloc=0,maxlen=0,wordloc,wordlen;
printf("please input string:");
gets(str);
i=0;
while(str[i]!='\0')
{
while(str[i]==' ')
i++;
wordloc=i;
wordlen=0;
while(str[i]!='\0'&&str[i]!=' ')
{
wordlen++;
i++;
}
if(wordlen>maxlen)
{
maxloc=wordloc;
maxlen=wordlen;
}
}
printf("the max word is:");
for(i=0;i<maxlen;i++)
printf("%c",str[maxloc+i]);
printf("\n");
}
输出一句话中最长的单词
最新推荐文章于 2022-08-27 20:34:34 发布