- #include<stdio.h>
- int maxWord(char str[]);
- int main()
- {
- char a[]="You cannot change what you refuse to confront";
- maxWord(a);
- return 0;
- }
- int maxWord(char str[])
- {
- int i = 0,max = 0,d = 0,c = 0;
- while (str[i] != '\0')
- {
- int n = 0;
- while (str[i] != ' ' && str[i] != '\0' )
- {
- n ++;
- i ++;
- }
- if (n > max)
- {
- max = n;
- c = i;
- d = i - n;
- printf("%d\n",d);
- }
- i++;
- }
- printf("最长单词的长度为:%d\n",max);
- printf("最长的单词为:");
- for ( i = d ; i <= c- 1; i ++)
- { printf("%c",str[i]);
- }
- printf("\n");
- return max;
- }
复制代码
|
|