对于有求字符串中最长单词,问题,若有并列怎么处理了?
#include<stdio.h>#include<string.h>
int main()
{int alp(char);
int longest(char[]);
int i;
char line[100];
printf("请输入");
gets(line);
printf("最长的是");
for(i=longest(line);alp(line[i]);i++)
printf("%c",line[i]);
return 0;
}
int alp(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,i,flag=1,place=0,point;
for(i=0;i<=strlen(string);i++)
if(alp(string[i]))
if(flag)
{point=i;
flag=0;}
else
len++;
else{flag=1;if(len>=length)
{length=len;place=point;len=0;}}
return(place);}