#include<stdio.h>//header file
#include<conio.h>//header file
#include<string.h>//header file
void main() //starting of the main() function
{
int c=0,m=0,p,i,l,l1; //declaration of the variables
char a[10],b[10];
clrscr();
printf("program that checks whether a string exists in another string ");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter any two strings");//taking input from the user
scanf("%s %s",&a,&b);
l=strlen(a);
l1=strlen(b);
if(l1<=l)
{
for(i=0;i<l;i++)
{
if(b[m]==a[i])
{
p=i;
while(b[m]==a[p])
{
if(b[m]=='\0')
{
break;
}
m++;
c++;
p++;
}
if(c==l1)
{
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe substring exists");//printing output
getch();
exit(0);
}
else
{
c=0;
m=0;
}
}
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nsubstring doesnot exists");//printing output
getch();
exit(0);
}
if(l1>l)
{
for(i=0;i<l1;i++)
{
if(b[i]==a[m])
{
p=i;
while(b[p]==a[m])
{
if(a[m]=='\0')
{
break;
}
m++;
c++;
p++;
}
if(c==l)
{
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe substring exists");//printing output
getch();
exit(0);
}
else
{
c=0;
m=0;
}
}
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nsubstring doesnot exists");//printing output
getch();
exit(0);
}
}