int FindStr(char* str, int strsize, char* fstr, int from)
{
for(int i=from, j=0; i<strsize; i++)
{
if(str[i]==fstr[j])
j++;
else
{i-=j; j=0;}
if(fstr[j]=='\0')
return i-j+1;
}
return -1;
}
The function searches for a string fstr
in str
and returns its index in str
if found, otherwise, it will return -1. It's also possible to specify where to start searching in the string.
My question is, can I optimize this function further? Also, do you see any potential problems in this function?