6 unsigned int i
, j
, k
, l
;
7 unsigned int matches
= 0;
10 /* Text size 7, pattern size 3, so the last element would be 7 - 3 + 1 = 5 */
11 for (y
= 0; y
< n
- m
+ 1; y
++) {
13 for (x
= 0; x
< n
- m
+ 1; x
++) {
15 k
= y
; /* reset text's vertical k (not to 0 but to the number of vertical loops) */
17 for (l
= 0; l
< m
; l
++) {
19 i
= x
; /* reset text's horizontal i (not to 0 but to the number of horizontal loops) */
21 for (j
= 0; j
< m
; j
++) {
25 if ( pattern
[l
][j
] != text
[k
][i
] )
28 i
++; /*increase horizontal drift*/
31 k
++; /*increase vertical drift*/
34 /* If we reached here we should have a match */
40 printf("Naive: %i\n",matches
);