Bugfix: Fix previous commit by reporting correctly the matches
[2dmatching.git] / naive.c
blobff080866680aaca8c651dfd2551b046553cc5dfe
1 #include "code.h"
3 unsigned int naive( char **text, char **pattern, int m, int n )
5 unsigned int i, j, k, l;
6 unsigned int matches = 0;
7 unsigned int x, y;
9 /* Text size 7, pattern size 3, so the last element would be 7 - 3 + 1 = 5 */
10 for (y = 0; y < n - m + 1; y++) {
12 for (x = 0; x < n - m + 1; x++) {
14 k = y; /* reset text's vertical k (not to 0 but to the number of vertical loops) */
16 for (l = 0; l < m; l++) {
18 i = x; /* reset text's horizontal i (not to 0 but to the number of horizontal loops) */
20 for (j = 0; j < m; j++) {
22 if ( pattern[l][j] != text[k][i] )
23 goto newline;
25 i++; /*increase horizontal drift*/
28 k++; /*increase vertical drift*/
31 /* If we reached here we should have a match */
32 matches++;
34 newline: ;
37 return matches;