#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void SEARCHING_PATTERN(char t[50],char p[50])
{
int s,r,max,i,j,k=-1,comp=0;
s=strlen(t);
r=strlen(p);
max=s-r+1;
//SEARCHING FOR PATTERN//
for(i=0;i<=max;i++)
{
for(j=0;j<r;j++)
{
k=i;
if(p[j]==t[i+j])
{
comp++;
if(comp==r)
{
goto LOCK;
}
}
else
{
k=-1;
comp=0;
break;
}
}
}
LOCK:
if(k>-1)
{
printf("\nPATTERN IS AT LOCATION %d",k+1);
}
else
{
printf("\n\aSORRY PATTERN CANN'T FIND.");
}
}
void main()
{
int k=-1,comp=0;
char t[50],p[50],c;
clrscr();
printf("ENTER TEXT = ");gets(t);
PATTERN:
printf("ENTER PATTERN = ");gets(p);
SEARCHING_PATTERN(t,p);
printf("\nFIND PATTERN AGAIN ? (Y/N)..");
c=getch();
if(c=='y'||c=='Y')
{
k=-1;
comp=0;
goto PATTERN;
}
else
exit(0);
}