I have implemented strstr() but the code has is not working please help:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
char* mystrstr(char*,char*);
int main()
{
char *s1,*s2,*flag;
printf("Enter a string:\n ");
gets(s1);
printf("Enter a word to find in it:\n");
gets(s2);
flag=mystrstr(s1,s2);
if(flag)
printf("Word found\n");
else
printf("Word not found");
getch();
return 0;
}
char* mystrstr(char* s1,char* s2)
{ int flag=0,j,i;
char* temp;
for(i=0;i<strlen(s1);i++)
{ if(*(s1+1)==s2[0])
{
for(j=1;*s2;j++)
{
if(*(s1+i)==*(s2+j))
flag=1;
else
flag=0;
}
}
}
if(flag)
{
temp=(char*)malloc(sizeof(char*));
itoa(j,temp,10);
return *temp;
}
return 0;
}