Re: Pattern Matching

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

char table [1024][1024];

int strnmcmp (char *src, char *des, int m, int n) {
  int i, j;
  for (i = m, j = 0;  i <= n; i++, j++)
    if (src [j] != des [i])
      return -1;
return 0;
}

//  strncat (p, src+m, n-m);

int main (void) {
    int ch;
    int i, j, k, n, length, notice;
    int c;
    char text [] = "ABBACABABB";

    for (n = 'A' - 'A';  n < ('C' - 'A')+1;  n++) {
      table [n][0] = n + 'A';
      table [n][1] = 0;
    }


    for (i = 0, j = 1, length = 1;  i < strlen (text); ) {
      for (; j < strlen (text); ) {
        for (k = 0;  (k < n) \&amp;\&amp; (strncmp (table [k], text+i, j-i) != 0);  k++);
        if (k >= n) {
          printf ("%i %sn", notice, table [notice]);
          strncpy (table [n], text+i, j-i);
          j--;
          n++;
          break;
        }
        else if (k < n) {
          notice = k;
          j++;
        }
      }
      i = j;
    }
    for (i = 0;  i < n; i++) {
      printf ("%sn", table [i]);
    }

return 0;
}