String Search

Program to search a string

#include < stdio.h>
#include < conio.h>
#include < string.h>
main()
{
int i,j,k=0;
char a[200],b[50];
clrscr();
printf("\nEnter the string : ");
gets(a);
printf("\nEnter the string to be found : ");
gets(b);
for(i=0;a[i]!='\0';i++)
{
if(b[0]==a[i])
{
k=1;
for(j=0;b[j]!='\0';j++)
{
if(a[i+j]!=b[j])
{
k--;
break;
}
}}
if(k==1)
break;
}
if(k==1)
printf("Found");
else
printf("Not found");
getch();
}

0 comments: