I need to make a recursive function, that gets two char arrays, and return the first index where "subStr" appear in the "str".
Signature of the function:
int strIndex(char str[], subStr[]);
For example- for str="abcdebc" and subStr="bc", it will return 1(because 1 is the first index where subStr contained in str), and for str="ab" and subStr="ab" it will return 0. If subStr doesn't contained in str(for example str="abc", subStr="aa"), it will return -1.
This is what I tried to do:
int strIndex(char str[], char subStr[])
{
if (strcmp(str, subStr) == 0)
return 0;
else if (strcmp(str + (strlen(str1) - strlen(subStr)), subStr) == 0)
return strlen(str) - strlen(subStr);
else
//return without the last element of "str" array
}
but does it possible to call in recurstion without the lest element of array?