#include<stdio.h>
#include<conio.h>
void main()
{
char str[80],search[10];
int count1=0,count2=0,i,j,flag;
clrscr();
puts(“Enter a string:”);
gets(str);
puts(“Enter search sub string:”);
gets(search);
while (str[count1]!=’\0′)
count1++;
while (search[count2]!=’\0′)
count2++;
for(i=0;i<=count1-count2;i++)
{
for(j=i;j<i+count2;j++)
{
flag=1;
if (str[j]!=search[j-i])
{
flag=0;
break;
}
}
if (flag==1)
break;
}
if (flag==1)
puts(“SEARCH SUCCESSFUL!”);
else
puts(“SEARCH UNSUCCESSFUL!”);
getch();
}
/*——————————
Output
Enter a string:
Hello how are you?
Enter search sub string:
how
SEARCH SUCCESSFUL!
——————————*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
- C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string
- C program to check whether a given number is prime or not and output the given number with suitable message
- Sample – Program to enter a string and find its length.
- C program to accept N numbers sorted in ascending order and to search for a given number using binary search. Report success or failure in the form of suitable messages
