Boyer-Moore algorithm error

0

I'm studying how to count how many times a string appears in the other, and I found that site Link of the site , it has the algorithm of Buyer-Moore, which finds number of occurrences of a in b, but only that when I pass the values the function returns 1, when it should return 6, I am making some mistake in the call function

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int trivial ( char a[], int m,  char b[], int n)
{
   int i, j, k, ocorre = 0;
    for (k = m; k <= n; ++k)
    {
        for (i = m, j = k; i >= 1; --i, --j)
         if (a[i] != b[j]) break;
       if (i < 1) ++ocorre;
   }
  return ocorre;
}

int main(int argc, char** argv)
{

    char a[] = "78954";
    char b[] = "7895478954789547895447895478954";
    int tamA = strlen(a);
    int tamB = strlen(b);
    int resultado = trivial(a, tamA, b, tamB);
    printf("%d\n", resultado);
    return 0;
 }
    
asked by anonymous 06.09.2018 / 13:29

0 answers