#includeint Longest(char *, int *); int Longest(char str[], int *t) { char ch; int max = 0, c = 0, place, word = 0,i = 0, local, temp; *t = temp = 0; for(; str[i] ; i++) { ch = str[i]; if(ch == ' ') { word = 1; if(max < c) { local = place; max = c; *t = temp; } } else if(ch >= 'a'&&ch<='z'||ch>='A'&&ch<='Z') { if(word == 1) { c = 1; place = i; word = 0; temp++; } else c++; } } if(max < c) { local = place; max = c; *t = temp; } return local; } int main() { char s[] = " rhkiilabc budf jkshd lsielid "; int i, j; i = Longest(s, &j); printf("%sn",s); printf("最长的单词在第%d个n", j); for(;s[i]!= ' '&&s[i] != ' ';i++) printf("%c",s[i]); return 0; }



