当前位置: 代码迷 >> C语言 >> 输入一行字符,输出最长的单词的问题
  详细解决方案

输入一行字符,输出最长的单词的问题

热度:133   发布时间:2007-04-22 18:58:02.0
输入一行字符,输出最长的单词的问题
题目要求是输入一行字符,将字符串中最长的单词输出,前面的函数应该没问题.是按照潭浩强的一本答案书上的N-S图写的
#include<stdio.h>
#include<string.h>
int positon(char str[])
{
int i,len=0,length=0,flag=0,place,point;
for (i=0;i<=strlen(str);i++)
{
if ('a'<=str[i]<='z'||'A'<=str[i]<='Z')
{
if (flag==0)
{
point=i;
flag=1;
}
else len++;
}
else
{
flag=0;
if (length>len)
{
length=len;
place=point;
len=0;
}
}
}
return(place);
}
main()
{
int positon(char str[]);
int i,j;
char str[80];
printf("请输入一个字符串\n");
scanf("%s",str);
j=positon(str[80]);
for(i=j;str[i]!=' ';i++)
printf("%c",str[i]);
}
错误是cannot convert parameter 1 from 'char' to 'char []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
搜索更多相关的解决方案: 单词  字符  输出  输入  

----------------解决方案--------------------------------------------------------
j=positon(str[80]);

改为:j=positon(str);
----------------解决方案--------------------------------------------------------

我对参数的传递感觉很模糊.有时候对,有时候错.能具体的说一下,要不告我看什么书


----------------解决方案--------------------------------------------------------
潭C
----------------解决方案--------------------------------------------------------
  相关解决方案