程序1:
#include<stdio.h> main()
{ static char s[]={"you make me happy when days are grey."},*t; int max=0,len=0; t=s;
while(*t!='.') { while(((*t<='Z')&&(*t>='A'))||((*t<='z')&&(*t>='a')))
{ len++;
t++;
}
if(max<len)
max=len;
len=0; t++; }
printf("max=%d",max); }
程序2:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define N 100
char *maxlenword(char statement[],char maxword[]) {
int i = 0,j;
char word[N];
maxword[0] = '\0';
for(i = 0; statement[i]; i++) {
if(!isalpha(statement[i++])) continue;
--i;
j = 0;
while(statement[i] && isalpha(statement[i]))
word[j++] = statement[i++];
word[j] = '\0';
if(strlen(maxword) < strlen(word))
strcpy(maxword,word);
}
return maxword;
}
int main() {
char a[N] = {'\0'};
char b[N] = {'\0'};
printf("请输入
字符串:\n");
gets(a);
maxlenword(a,b);
printf("最长单词长为:%d\n",strlen(b));
printf("最长单词为:\"%s\"\n",b);
return 0;
}