C program to find a given word in a string


/* C program to find a given word in a string. */

#include"stdio.h"
main()
{
int i=0,j=0,f=0;
char str1[100],str2[100];

printf("Enter the string : ");
gets(str1);

printf("Enter the string to find : ");
gets(str2);
for(i=0;str1[i];i++)
{
f=0;
if(str1[i]==str2[0])
f=1;
for(j=1;str2[j];j++)
{
if(str1[i+j]!=str2[j]);
{
f=0;
break;
}
}
if(f==1)
break;
}
if(f==1)
printf("%s is found",str2);
else
printf("%s is not found”,str2);

}

Output:




Comments

Popular Posts