1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I dont know where is the error

Discussion in 'C' started by mdinu, Feb 9, 2007.

  1. mdinu

    mdinu New Member

    Joined:
    Feb 9, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Feb 9, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    You dont have the closing bracket for KMP
     

Share This Page