char str[] = "my beautiful teacher is ";
unsigned long int a = 0; //长整型变量
a = strlen(str);
int count = 0, max = 0 ;
for (int i = 0; i < a; i ++) {
if (str[i] != ' ') {
count ++;
continue;
}
max =count > max ? count : max;
count = 0;
}
printf("%d\n",max); //求最大值
printf("最长单词为:");
for (int i = 0; i < a; i ++) {
if (str[i] != ' ') {
count ++;
if (count == max) {
for (int j = i - max ; j <= i ; j ++) {
printf("%c", str[j]);
}
}
continue;
}
count = 0;
}