problem with recursion and string
hi guys, i need help with this algorithm, given a string and a character, the function char *lastocc(char *s, char c) has to return a pointer to the last occurrence of the character c in the string *s, for example if the word is swimming and the char is i it shoud return ' ing ', here's what i wrote:
Code:
char *lastocc(char *s, char c)
{
if(*s == '\0') {
return;
}
else if(*s != c) {
*lastocc(s+1, c);
}
else if(*s == c) {
printf("%s", s);
*lastocc(s+1, c);
}
}
the problem is that it returns every occurrence of the character (hence imming and ing) while it should return only the last one, i still cant figure out how to do that, any suggestion?