Accepted
/in/foo.c: In function 'main': /in/foo.c:10:5: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(line); ^~~~ In file included from /in/foo.c:1:0: /usr/include/stdio.h:640:14: note: declared here extern char *gets (char *__s) __wur __attribute_deprecated__; ^~~~ /in/foo.c: In function 'longest': /in/foo.c:46:12: warning: 'point' may be used uninitialized in this function [-Wmaybe-uninitialized] return (place); ^ /tmp/ccz7SJKK.o: In function `main': foo.c:(.text.startup+0x9): warning: the `gets' function is dangerous and should not be used.
代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int alphabetic(char c);
int longest(char[]);
int i;
char line[100];
gets(line);
for (i=longest(line);alphabetic(line[i]);i++)
printf("%c",line[i]);
printf("\n");
return 0;
}
int alphabetic(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,i;
for (i=0;i<=strlen(string);i++)
if(alphabetic(string[i]))
if(flag)
{
point=i;
flag=0;
}
else
len++;
else
{
flag=1;
if(len>=length)
{
length=len;
place=point;
len=0;
}
}
return (place);
}