for(int x = 0; (x < int(strlen(Pattern))); x++)
{
if(Paragraph[i][x] != Pattern[x] )//Ignore this part, what you did here is right
The = 0;
else
The++;
}
//In main...
int main()
{
int The = 0;
if (FindThe(int The, char Paragraph[], char Pattern[]) == int(strlen(Pattern))
cout << "a counter variable goes here..."<<
}
for(int i(0); i < 500; i ++)
Should instead be : for(int i(0); i < (int)strlen(Paragraph); i ++)
Line 7 of main()
char Pattern[4] = {'t','h','e'}; You have actually made a 2d array. Maybe this is what you want instead?
char Pattern[4] = "the";
Line 20: if ( FindThe (The, Paragraph, Pattern) == ( strlen ( Pattern ) ) )
Since your function is returning a type int, cast the strlen() to int if ( FindThe (The, Paragraph, Pattern) == int( strlen ( Pattern ) ) )
#include <iostream>
usingnamespace std;
int FindThe (int The, char Paragraph[], char Pattern[])
{
int toRet = 0;
for(int i = 0; i < int(strlen(Paragraph)); i ++)
{
The = 0;
if (Paragraph[i] == Pattern[0])
{
for(int x = 0; (x < int(strlen(Pattern))); x++)
{
if(Paragraph[i+x] == Pattern[x] )
The++;
else
The = 0;
if (The == int (strlen(Pattern)))
toRet++;
}
}
}
return toRet;
}
int main()
{
char Pattern[] = "the";
char Paragraph[] = "There once was a man who was the king's greatest advisor and this man came to be known for his wisdom and kindness.";
//int NumLetters(0);
//int NumWhite(0);
//int NumWords(0);
int The = FindThe (The, Paragraph, Pattern);
//int count(0);
//cout <<"There are " << NumLetters << " Total letters and " << NumWhite + 1 << " total words" << endl;
cout << "'The' occurs " << The << " times " << endl;
return 0;
}