You are on page 1of 1

#include <stdio.

h>
#include<string.h>
#include<stdlib.h>
void main()
{
char*my_strstr( char*s1, char*s2);
char str1[10],str2[10];
printf("enter str1:");
scanf("%s",str1);
printf("enter str2:");
scanf("%s",str2);
char* p=my_strstr(str1,str2);
if(p[1]){
printf("substring is :");
for(int i=0;i<strlen(str2);i++)
printf("%c",p[i]);}
else{
printf("NULL");
}
}
char*my_strstr(char*s1,char*s2)
{
int a=0,b=0,k=0,c=0;
char*result=NULL;

while(s1[a]!='\0')
a++;
while(s2[b]!='\0')
b++;
result=(char*)malloc(b);
for(int i=0;s1[i]!='\0';i++)
{

c=0;
for(int j=0;s2[j]!='\0'&&j<=b;){
if(s1[i]==s2[j])
{
c=1;

}
j++;
}
if(c==1){
result[k]=s1[i];
k++;
}
}

return result;
}

You might also like