I dont know where is the error

mdinu's Avatar, Join Date: Feb 2007
Newbie Member
Code:
#include <stdio.h>
#include <io.h>
//define XSIZE=100;
  int m,n;
  char *x,*y;
void preKmp(char *x, int m, int kmpNext[]) {
   int i, j;

   i = 0;
   j = kmpNext[0] = -1;
   while (i < m) {
      while (j > -1 && x[i] != x[j])
         j = kmpNext[j];
      i++;
      j++;
      if (x[i] == x[j])
         kmpNext[i] = kmpNext[j];
      else
         kmpNext[i] = j;
   }
}

void KMP(char *x, char *y) {
   int i, j, kmpNext[100], m,n;

   /* Preprocessing */
   preKmp(x, m, kmpNext);

   /* Searching */
   i = j = 0;
   while (j < n) {
      while (i > -1 && x[i] != y[j])
         i = kmpNext[i];
         printf("i=");scanf("%s/n",&i);
      i++;
      j++;
      if (i >= m) {
            printf("j-i");
        scanf("%d-%d",&j-&i);
         i = kmpNext[i];
      }
  }

int main()
{
  int m, n;
  char *x, *y;
 // printf("String: %s\n",&x);
  printf("string: ");scanf("%s",&x);
// printf("m: "); scanf("%d\n", m);
  printf("Pattern: "); scanf("%s", &y);
  //printf("n: "); scanf("%d\n", n);
   printf("KMP=");
   KMP( x, y);

}


#include <stdio.h>
#include <io.h>
//define XSIZE=100;
  int m, n;
  char *x, *y;
void preKmp(char *x, int m, int kmpNext[]) {
   int i, j;

   i = 0;
   j = kmpNext[0] = -1;
   while (i < m) {
      while (j > -1 && x[i] != x[j])
         j = kmpNext[j];
      i++;
      j++;
      if (x[i] == x[j])
         kmpNext[i] = kmpNext[j];
      else
         kmpNext[i] = j;
   }
}

void KMP(char *x, char *y) {
   int i, j, kmpNext[100], m,n;

   /* Preprocessing */
   preKmp(x, m, kmpNext);

   /* Searching */
   i = j = 0;
   while (j < n) {
      while (i > -1 && x[i] != y[j])
         i = kmpNext[i];
         printf("i=");scanf("%s/n",&i);
      i++;
      j++;
      if (i >= m) {
            printf("j-i");
        scanf("%d-%d",&j-&i);
         i = kmpNext[i];
      }
   }
}

int main()
{
  int m, n;
  char *x, *y;
 // printf("String: %s\n",&x);
  printf("string: ");scanf("%s",&x);
// printf("m: "); scanf("%d\n", m);
  printf("Pattern: "); scanf("%s", &y);
  //printf("n: "); scanf("%d\n", n);
   printf("KMP=");
   KMP( x, y);

}
i use lcc but i need help I do not find the mistake pls
Thanks in advance

Last edited by shabbir; 9Feb2007 at 17:35.. Reason: Code formatting
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You dont have the closing bracket for KMP