Need a project done?

C++ Programming Developer

Search This Blog

C++ Program to Search a keyword (in character type array or) through the user entered text.

C++ Program to search through character type array
/*
C++ Program to Search a keyword through the user entered text.
*/









//#include <iostream>

#include <iostream>
using namespace std;

int main()
{
cout << "Write somethig:\n";
char *string = new char [100];
cin.getline (string,100,'\n');

cout << endl << "Search: ";
char *keyword = new char [10];
cin.getline (keyword,10,'\n');

for (int i = 0, j = 0, k = 0, m = 0; string[j] != '\0'; i++,j++)
{
if (keyword[i] == '\0')
{
i = 0;
m = 0;
j = ++k;
}

if ( keyword[i] == string[j] )
{
m++;
}
if (m == strlen(keyword))
{
cout << "FOUND" << endl;
exit (0);
}
}
cout << "Not Found" << endl;
return 0;
}
"Don't let anyone ever make you feel like you don't deserve what you want."