Write the function my_strrchr(). The function has two parameters: a const char * s pointing to the first character in a C-style string, and a char, c. Return a pointer to the last appearance of c appearing inside s and NULL (0) if c does not appear inside s.
is this the right way to go backward, grap the first time the char appear and return it?
const char * my_strrchr(const char * s, char c)
{
int b = 0;
char first = *s;
for(int i = strlen(s)-1; i > 0 ; i--)
{
if(s[i] == c)
{
return s;
break;
}
}
return '\0';
}
int main()
{
char cstr[50] = "Abadabadoo!";
cout << "\nmy_strrchr(cstr, 'a') expects adoo!" << endl;
cout << " -- " << my_strrchr(cstr, 'a') << endl;
}