开发者社区 问答 正文

请问这个c程序哪里出错了? 谢谢!!

题目要求:输入一行字符,将其中最长的单词输出。

#include 
int main()
{ void f(char s[]);
char s[100];
printf("enter a sentence:");
scanf("%s",s);
f(s);
}
void f(char s[])
{
int i,n,m=0,sum=0,temp=0;
for(n=0;s[n+m]!='\0';n++)
{ for(i=0;s[m+n+i]!=' ';i++)
sum=sum+i;
if(i>m) {temp=m+n;m=i;}
}
for(n=temp;n<=temp+m;n++)
printf("%c",s[n]);
}
同问0 |浏览334| 收藏0 |分享

展开
收起
a123456678 2016-03-23 13:59:46 1657 分享 版权
1 条回答
写回答
取消 提交回答
  • int main()里的void f(char s[]);移到int main()上面就对了。

    2019-07-17 19:10:53
    赞同 展开评论
问答地址: