#include<stdio.h>
#include<string.h>
int alph(char c)
{
if((c>=‘a‘&&c<=‘z‘)||(c>=‘A‘&&c<=‘Z‘))
return(1);
else
return(0);
}
int longest(char string[])
{
int len=0,length=0,flag=1,place=0,point;
unsigned int i;
for(i=0;i<=strlen(string);i++)
if(alph(string[i]))
if(flag)
{
point=i;
flag=0;
}
else
len++;
else
{
if(len>length)
{
length=len;
place=point;
}
flag=1;
len=0;
}
return(place);
}
void main()
{
int i;
char line[100];
printf("in:");
gets(line);
printf("The longest word is:");
for(i=longest(line);alph(line[i]);i++)
printf("%c",line[i]);
putchar(‘\n‘);
}
时间: 2024-12-16 08:33:47