输入一个单词和一个句子,判断单词是否在句子中,请教各位这个程序有什么问题

daiqiang555 2011-10-09 09:54:04
# include<iostream.h>
# include<string.h>
bool FindFavorite( char[],char[]);
int main()
{
char phrase[80],word[15],answer[5];
bool Find_it;
do
{
cout<<"\n请输入你最喜欢的单词===>";
cin.getline(word,15);

cout<<"\n\n请输入一句换或者短语===>";
cin.getline (phrase,80);
Find_it= FindFavorite( phrase,word);
if( Find_it=true)
cout<<"\n找到了单词==>"<<word<<endl;
else
cout<<"\n未找到单词==>"<<endl;

cout<<"继续输入YES or NO";
cin.getline( answer, 5);
}
while(strcmp(answer,"yes")==0);

return 0;
}
bool FindFavorite(char phrase[],char word[])
{
bool result;
char *IsIthere;
IsIthere=strstr(phrase,word);
if (IsIthere==NULL)
result=false;
else
result=true;
return(result);
}
...全文
672 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lulusophia 2011-10-09
  • 打赏
  • 举报
回复
再加上头文件

# include<iostream>
# include<string.h>
using namespace std;
lulusophia 2011-10-09
  • 打赏
  • 举报
回复

if( Find_it==true)
cout<<"\n找到了单词==>"<<word<<endl;
else
cout<<"\n未找到单词==>"<<endl;



LZ把if语句改掉就OK啦!
ryfdizuo 2011-10-09
  • 打赏
  • 举报
回复
#include<iostream>
#include<string>
using namespace std;
试试。
bdmh 2011-10-09
  • 打赏
  • 举报
回复
KMP算法查找子串,或者自己遍历比对

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧