Sub-String Search
#include< stdio.h>
#include< conio.h>
#include< string.h>
main()
{
clrscr();
int l,i,j=0,z=0,k=0;
char a[200]="",b[20];
printf("\n\n enter the string:");
for(i=0;a[i-1]!='\n';i++)
a[i]=getchar();
a[i]='$';
printf("\n\n enter the word to be found:");
scanf("%s",b);
l=strlen(b);
for(i=0;a[i]!='$';i++)
{
if(a[i]==b[0]||z==0)
{
j=0;
k=0;
z=1;
}
if(a[i]!=b[j])
{
k++;
i--;
}
j++;
if(k==0&&j==l)
break;
}
if(k==0)
printf("\n ***found***");
else
printf("\n ###not found###");
getch();
}
0 comments:
Post a Comment