add strrchr()

This commit is contained in:
NAKAMURA Gou
2015-11-26 20:07:26 +09:00
parent 06a7889e1f
commit e805249651
2 changed files with 15 additions and 1 deletions

View File

@ -23,6 +23,7 @@ int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strstr(const char *haystack, const char *needle);
char *strchr(const char *s, int n);
char *strrchr(const char *s, int n);
void *memcpy(void *dest, const void *src, size_t n);
void *memcpy_long(void *dest, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);

View File

@ -95,7 +95,20 @@ char *strchr(const char *s, int n) {
}
return NULL;
}
char *
strrchr(const char *s, int c)
{
const char *last = NULL;
do {
if (*s == c) {
last = s;
}
} while (*(s++));
return (char *)last;
} /* strrchr() */
char *strstr(const char *haystack, const char *needle)
{