| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 462 人关注过本帖
标题:[求助]求最长单词问题
只看楼主 加入收藏
rock1013
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-6-23
收藏
 问题点数:0 回复次数: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



搜索更多相关主题的帖子: 单词 
2007-06-30 13:54
快速回复:[求助]求最长单词问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021612 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved