C PROGRAM TO ACCEPT STRING & SUBSTRING AND CHECK SUBSTRING PRESENT IN STRING OR NOT | Indian Shout

You are here: » C PROGRAM TO ACCEPT STRING & SUBSTRING AND CHECK SUBSTRING PRESENT IN STRING OR NOT

C PROGRAM TO ACCEPT STRING & SUBSTRING AND CHECK SUBSTRING PRESENT IN STRING OR NOT

/* Write a C program to accept a string and a substring and check if the substring is present in the given string */

#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 substring:”);
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 substring:
how
SEARCH SUCCESSFUL!
——————————*/

ilook website
 
 

Categories:Uncategorized;Tags: , , , , , , ,

   

One Comment to “C PROGRAM TO ACCEPT STRING & SUBSTRING AND CHECK SUBSTRING PRESENT IN STRING OR NOT”

  1. Shaunak says:

    Really its a very good site to provide the exact & understandable solution to new C learners.

Leave your comment here: