void printstr(char *str);

int _strlen(char *s)
{
  int len;
  for (len = 0; s[len]; len++)
    ;
  return len;
}

char *_strrchr(char *s, int c)
{
  char *ss = s;
  s += _strlen(s);
  while (1) {
    if (*s == c)
      break;
    if (s == ss) {
      s = 0;
      break;
    }
    s--;
  }
  return (char *)s;
}

int main()
{
  char *p;

  p = _strrchr("ABCDEFG", 'A');
  printstr(p);

  p = _strrchr("ABCDEFG", 'C');
  printstr(p);

  p = _strrchr("ABCDABCD", 'A');
  printstr(p);

  p = _strrchr("ABCDABCD", 'D');
  printstr(p);

  p = _strrchr("ABCDEFG", 'a');
  if (p)
    printstr("ERROR");

  return 0;
}
