searching backwards through a string

Jan 28, 2008 at 12:23pm
Is there a way to search backwards through a character array without using the STL? I've tried using strrchr() but I can't get it to search the 2nd instance backwards.
thanks
friz
Jan 28, 2008 at 6:59pm
An option would be to create your own upgraded version of strrchr, taking an additional parameter that points to the last character in the string to be searched:
1
2
3
4
5
6
7
const char * mystrrchr ( const char * str, int character, char * end )
{
  while (end!=str)
    if (*end == character) return end;
    else --end;
  return 0;
}
Jan 29, 2008 at 8:40am
Thanks I'll try this out.
Topic archived. No new replies allowed.