当前位置: 代码迷 >> C语言 >> [求助]求最长单词问题
  详细解决方案

[求助]求最长单词问题

热度:395   发布时间:2007-06-30 13:54:07.0
[求助]求最长单词问题

//输出句子中最长的单词
#include<stdio.h>
int num=0;
char k[];
void longest(char a[])
{

int i,t=0,h,max=0,d,b,c=0,p;
for(i=0;a[i]!='\0';i++)
{
if (t=0)
{
t=1;
h=i;
}
if (a[i]==' ')
{ t=0;
if (max<(i-h))
{
max=(i-h);
k[0]='\0';
d=h;
b=i;
c=0;
num=1;
for (p=d;p<=b;p++)
{
k[c]=a[p];
c=c+1;
}
}
if (max==(i-h))
{
num=num+1;
d=h;
b=i;
for (p=d;p<=b;p++)
{
k[c]=a[p];
c=c+1;
}

}

}
}

}

void main()
{
char chara[100];
gets (chara);

longest(chara);

printf("there is(are) %d longest word(s),%s",num,k);
}






C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(8) : error C2082: redefinition of formal parameter 'a'
C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(22) : error C2440: '=' : cannot convert from 'int' to 'char []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(26) : error C2440: '=' : cannot convert from 'char []' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(35) : error C2440: '=' : cannot convert from 'int' to 'char []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(37) : error C2440: '=' : cannot convert from 'char []' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\c\Cpp1.cpp(58) : warning C4508: 'main' : function should return a value; 'void' return type assumed



搜索更多相关的解决方案: 单词  

----------------解决方案--------------------------------------------------------
  相关解决方案