最长单词

#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');
}

posted @ 2015-01-09 18:32  zach96  阅读(194)  评论(0编辑  收藏  举报