Burte Force String Match

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char text[]={"SmartProgrammerOn"},strn[11];
int t,s;
cout<<"Given Data is : \t"<<text;
cout<<"\nWhat you want search(max size 10): ";
cin>>strn;
t=strlen(text);
s=strlen(strn);
int i,j=0;
for(i=0;i<t;i++)
{
j=0;
while (j<s&&strn[j]==text[i+j])
{
j=j+1;
if (j==s)
{
cout<<"String Match at location "<<i+1;
return 0;
}
}
}

cout<<"No result found.";
getch();
}
OutPut:

Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons