Given a string and a sub-string check if the sub-string is present in the string
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void) {
char *m,*s;
int mlen,slen;
int i,j,index,k,flag=1,fla=1;
m=(char*)malloc(sizeof(char));
s=(char*)malloc(sizeof(char));
scanf("%s",m);
scanf("%s",s);
mlen=strlen(m);
slen=strlen(s);
for(i=0;i<mlen;i++)
{
flag=1;
fla=1;
if(*(m+i)==*s)
{
index=i;
k=i;
for(j=0;j<slen;j++)
{
if(*(m+k)==*(s+j))
k++;
else
{
flag=0;
break;
}
}
if(flag)
{
printf("found at index %d\n",index);
fla=0;
}
}
}
if(fla)
printf("not found");
return 0;
}