#include <stdio.h>
int word_len(char *s_word)
{
int i_len=0;
while (*s_word!=' '&&*s_word!=0) {
i_len++;
s_word++;
}
return i_len;
}
int main()
{
char s_string[200];
char *p=s_string-1; /*下面p=strchr(p+1,' ')保证开始的时候p指向
字符串第一个字符所以p=s_string-1*/
char *p_current_longest=s_string;
gets(s_string);
do {
p=strchr(p+1,' ');
if (p!=NULL) {
if (word_len(p_current_longest)<word_len(p+1))
p_current_longest=p+1;
}
} while (p!=NULL);
while (*p_current_longest!=' '&&*p_current_longest!=0) {
putchar(*p_current_longest);
p_current_longest++;
}
getchar();
return 0;
}
Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.