下面是我写的代码,if
语句是判断天气是否在句子中,但是想要有一个功能。任何人都可以检查这个和什么
#include <iostream>
#include <cstdio>
#include <string>
#include <iomanip>
using namespace std;
int main ()
{
char sentence[50];
char search [50];
int numtimes = 0;
cout << "Enter a sentence: " << endl;
gets_s (sentence);
cout << endl;
cout << "Your sentence is: \n" << sentence << endl;
cout << "Enter a any word: " << endl;
gets_s (search);
cout << endl;
cout << "The word is: " << search << endl;
int i, len;
int j, lenS;
len = strlen(sentence);
lenS = strlen(search);
for (i = 0; i < len - lenS + 1; i++)
{
if (sentence[i] == search[0])
{
for (j = 0; j < lenS; j++)
{
if (sentence[i+j] != search[j])
break;
}
if (j == lenS)
{
cout << "search found\n";
break;
}
}
}
if (i == len - lenS +1)
{
return 1;
}
system("PAUSE");
return 0; }