My goal is to call a function and the function will return me 0 / 1 if the sent string has the
sent substring in it , I do not need to find its index
for example:
String : “Hello World”
SubString : “rl”
will return 1
String : “asssbdsd”
SubString : “ab”
will return 0
so I’ve come up with this solution :
int HasSubstr(char* mainStr, char* subStr)
{
if (!*subStr)
{
return 1;
}
if (!*mainStr)
{
return 0;
}
if (*mainStr == *subStr)
{
return HasSubStr(mainStr + 1, subStr + 1);
}
else
{
while(*(subStr -1))
{
subStr--;
}
return HasSubStr(mainStr + 1, subStr);
}
}
but it’s not a pure recursion and i need it to be a pure recursion
, help would be much applied
Yes this is homework
Don’t try to fit it all within one function.