Please Help me urgently

shahzaib198's Avatar, Join Date: Aug 2007
Newbie Member
Pattern Matching Code using table

Below is my code, i m given an assignment of it. please help me.
Well the problem that it is arrising is that the correct values after comparison are not coming. So please help me in this. in id[i][j].

it should be like
let say for pattern aaba
Output would be
Code:
      a           b
     aa         ab
     aaa       aab
     aaba      aabb
no finding no is a problem for me
it should be

like
Code:
      1         0
      2         0 
      2         3
      4         0
but it is not coming
please see the code

Code:
// i am labelling the area

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

#define SIZE strlen(pattern)

char *sstring(char s[100],int i,int l);
void remove_duplicates(void);
void sublists(void);

char column[20];
char pattern[20];
char sublist[21][20];
char table[21][20];

void main(void)
{
char string[100],temp[21][20],sl[20][20];
int id[10][10];
int count=0;
char t[10];
char *ptr;
ptr=t;

clrscr();

//first of all getting the pattern
printf("\n\nPlease Enter the Pattern : ");
gets(pattern);

//now making a copy of pattern for removing duplicates
strcpy(column,pattern);

//now removing duplicates
remove_duplicates();

//now making the sublist of the pattern
sublists();

 for(int i=0;i<strlen(pattern);i++)
 {
  strcpy(temp[i],sstring(pattern,0,count++));
}
count=0;

//this is the problem are
for( i=0;i<strlen(pattern);i++)

  {
  for(int j=0;j<strlen(column);j++)
    {
       strcat(temp[i],sstring(column,count++,1));

       printf("%10s ",temp[i]);

       for(int l=strlen(pattern)-1;l>=0;l--)
       {
	int counts=strlen(sublist[l])-1;   //2
	int comps=strlen(temp[i]);         //1
	int comp=0;
	int cp=l;

	    while(counts!=-1)
	    {  counts=strlen(sublist[cp])-1;   //2
	     if(temp[i][comp]==sublist[cp][counts])
	      { count--;
	       comp++;

	       if(comp==comps)
	       {
		  id[i][j]=l;
		  break;
	       }
	      }
	     else
		{
		   cp--;
		}

	      }
			cp=l;


       }

//till here 

       if (count==strlen(column)) count=0;

	//another loop for finding the position

       strcpy(temp[i],sublist[i]);
    }
  printf("\n");

  }

   printf("\n");



//printing

for(i=0;i<strlen(pattern);i++)
 {
 for(int j=0;j<strlen(column);j++)
  {

    printf("Q[%d]  ",id[i][j]);

   }
  printf("\n");
 }

//printf("\n\nPlease Enter the string: ");
//gets(string);


getch();

}



void remove_duplicates(void)
{

//this is done to remove duplicates

  for(int j=SIZE-1;j>=0;j--)
   {
    for(int k=0;k<j;k++)
     {
      if (column[j]==column[k])
       {
	column[j]='.';
       }
     }
   }
    for(int k=SIZE-1;k>=0;k--)
     {

      if (column[k]=='.')
       {
	for(int i=k;i<SIZE;i++)
	  column[i]=column[i+1];
       }

}

}





void sublists(void)
{
   int count=0;


for(int i=0;i<strlen(pattern)+1;i++)
{
  strcpy(sublist[i],sstring(pattern,0,count++));
}

sublist[0][0]='\0';
for(i=0;i<strlen(pattern)+1;i++)
 printf("\n\nThe substring @ q[%d] is : %s ",i,sublist[i]);
   printf("\n\n");

}




char *sstring(char s[100],int i,int l)
{
int count;
char sp[100];
count=0;
 while (count<l)
 {
 sp[count]=s[i];
 count=count+1;
 i=i+1;
 }
 sp[count]='\0';
  return (sp);
}

Last edited by shabbir; 13Aug2007 at 19:22.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Please read this urgently