Created
July 6, 2012 12:57
-
-
Save obstschale/3060031 to your computer and use it in GitHub Desktop.
Brute-Force Pattern Matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bruteforcematch(char S[ ], char P[ ]) // S is source string, P is pattern | |
{ | |
int n, m, i, j; | |
n = strlen(S); | |
m = strlen(P); | |
for (i = 0; i <= n – m; i++) // for each pattern comparison | |
{ | |
j = 0; | |
while(j < m && S[i+j] == P[j]) // each character comparison | |
{ j++; } // end while | |
if (j == m) | |
{ return i; } | |
else | |
{ return -1; } // not matched | |
} // end for | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brute-Force Pattern Matching
only suitable for small strings with very few repeated sequences.