Having problem in User Defined function which works like strstr function
Hello,
this is my yet another problem i have made 1 user defined function which works pretty much like strstr function defined in string.h but it's having problem. I have figured out the problem but don't know how to solve it. Here is the code! Please have a look and tell me how to solve it?
Code:
#include <iostream.h>
char* ustrstr(char s[],char t[])
{
int i,j;
char *temp;
for(i=0;s[i]!=NULL;i++)
{
j=0;
temp=&s[i];
while(t[j]==s[i] && s[i]!=NULL)
{
j++;
i++;
}
if(t[j]==NULL)
return temp;
if(s[i]==NULL)
i--;
}
return NULL;
}
int main(void)
{
char s[100],*j;
cout<<"\n\nEnter Any String :";
cin.getline(s,100);
j=ustrstr(s,"technology");
if(j==NULL)
cout<<"\n\nSubstring Not Found";
else
cout<<"\n\nSubstring Found :"<<j;
return 0;
}
Just give input as iliketechnology it works fine and then give ilikettechnology! :( it's not working i know where the problem is but dont know how to solve. Please help me