Runtime Error
/in/foo.c:2:6: warning: return type of 'main' is not 'int' [-Wmain] void main() ^~~~ /in/foo.c: In function 'main': /in/foo.c:6:3: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(str); ^~~~ 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__; ^~~~ /tmp/ccnbggqZ.o: In function `main': foo.c:(.text.startup+0xe): warning: the `gets' function is dangerous and should not be used.
代码
#include <stdio.h>
void main()
{
void fun(char str[],char word[]);
char str[80],word[20];
gets(str);
fun(str,word);
printf("%s\n",word);
}
void fun(char str[],char word[])
{
int i,j=0,w=0,k,th,t[10],lenth[10],len=0;
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' ') w=0;
else if(w==0)
{
t[j]=i;j++;
w=1;
}
}
j=0;
for(i=0;str[i]!='\0';i++)
{
len++;
if(str[i]==' ')
{
lenth[j]=len-1;
j++;
len=0;
}
}
k=lenth[0];
th=0;
for(i=0;lenth[i]!=0;i++)
if(k <lenth[i])th=i;
for(j=t[th],i=0;str[j]!=' ';j++)
{
word[i]=str[j];i++;
}
word[i]=0;
}