Page

C program for implement the pattern mattching

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char t[50],p[50];
int n,m,s,j,i,c;
clrscr();
printf("\n Enter the main string : ");
gets(t);
n=strlen(t);
printf("\n Enter the pattern : ");
gets(p);
m=strlen(p);
for(s=0;s<=n-m;s++)
{
i=s;c=0;
for(j=0;j<=m;j++)
{
if(t[i]==p[j])
{
i++;
c=1;
}
else
{
c=0;
break;
}
}
if(c==1)
printf("\n\nString found %d",s);
}
getch();
}

No comments:

Post a Comment