#include <iostream>
#include <string.h>
using namespace std;
bool findWords(const char *str, const char *dst)
{
char *strsrc = strdup(str);
char *p = strtok(strsrc, " ");
while(p)
{
if(0 == strcmp(p, dst))
return true;
else
p = strtok(NULL, " ");
}
return false;
}
int main()
{
cout<<"请输入要查找的单词:";
cin>>dst;
if(findWords(str, dst))
cout<<"Find it!\n";
else
cout<<"Cann't Find it!\n";
cout<<"Hello\n";
return 0;
}
#include <string.h>
using namespace std;
bool findWords(const char *str, const char *dst)
{
char *strsrc = strdup(str);
char *p = strtok(strsrc, " ");
while(p)
{
if(0 == strcmp(p, dst))
return true;
else
p = strtok(NULL, " ");
}
return false;
}
int main()
{
char str[100],dst[10];
cout<<"请输入源字符串:";
gets(str);cout<<"请输入要查找的单词:";
cin>>dst;
if(findWords(str, dst))
cout<<"Find it!\n";
else
cout<<"Cann't Find it!\n";
cout<<"Hello\n";
return 0;
}