#include<stdio.h>
#include<string.h>
int main()
{
int ju_re(char b[]);
char a[100];
int c;
printf("请输入一行文本:");
gets(a);
c = ju_re(a);
//printf("\n%d\n",c);
printf("\n最长单词为:");
for(c;a[c] !=' ';c++)
putchar(a[c]);
putchar('\0');
return 0;
}
int ju_re(char b[])
{
int i,e = 0,ha = 0,word = 0,count = 0,before,c;
for(i = 1;i <= strlen(b);i++)
{
before = i - 1;
if((before == 0 )&&( b[before] != ' '))
{
count++;
c = before;
if(b[i] != ' ')
{
word = 1;
}
}
if((b[i] != ' ' )&&( b[before] == ' '))
{
word = 1;
c = i;
}
if((b[i] == ' ' )&&( b[before] != ' '))
word = 0;
if(word == 1) count++;
if((word == 0 )&& (count > ha))
{
ha = count;
e = c;
}
if(word == 0) count = 0;
}
return(e);
}
#include<string.h>
int main()
{
int ju_re(char b[]);
char a[100];
int c;
printf("请输入一行文本:");
gets(a);
c = ju_re(a);
//printf("\n%d\n",c);
printf("\n最长单词为:");
for(c;a[c] !=' ';c++)
putchar(a[c]);
putchar('\0');
return 0;
}
int ju_re(char b[])
{
int i,e = 0,ha = 0,word = 0,count = 0,before,c;
for(i = 1;i <= strlen(b);i++)
{
before = i - 1;
if((before == 0 )&&( b[before] != ' '))
{
count++;
c = before;
if(b[i] != ' ')
{
word = 1;
}
}
if((b[i] != ' ' )&&( b[before] == ' '))
{
word = 1;
c = i;
}
if((b[i] == ' ' )&&( b[before] != ' '))
word = 0;
if(word == 1) count++;
if((word == 0 )&& (count > ha))
{
ha = count;
e = c;
}
if(word == 0) count = 0;
}
return(e);
}