Page

C Program To Find The Pattern In The String

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char t[50],p[20];
int n,m,i,j,s,f=0,c=0;
clrscr();
printf("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("string found %d",s);
f=1;
}
if(f==0)
{
printf("not found");
}
getch();
}

No comments:

Post a Comment