Daily Archives

One Article

Naive String Matching algo implementation in c++

using namespace std;

#include <iostream>
#include <conio.h>
#include <stdio.h>

string T = "this is awesome";
string M = "is";

int match() {
int flag=0;

for(int i=0; i <T.length() -M.length(); i++) {
if (T[i] == M[0]) {
flag =1;
for (int j=1; j<M.length(); j++) {

if(T[(i+j)] == M[j]) {

// flag=0;

}
else {
cout << "failure";
return -1;
}}

cout << "success , value of shift is : " << i ;
}
}

if (flag == 0) {

cout << "failure";

}
}

int main() {

match();
return 0;

< }