add strrchr()
This commit is contained in:
@@ -23,6 +23,7 @@ int strcmp(const char *s1, const char *s2);
|
|||||||
int strncmp(const char *s1, const char *s2, size_t n);
|
int strncmp(const char *s1, const char *s2, size_t n);
|
||||||
char *strstr(const char *haystack, const char *needle);
|
char *strstr(const char *haystack, const char *needle);
|
||||||
char *strchr(const char *s, int n);
|
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(void *dest, const void *src, size_t n);
|
||||||
void *memcpy_long(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);
|
int memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
|||||||
13
lib/string.c
13
lib/string.c
@@ -96,6 +96,19 @@ char *strchr(const char *s, int n) {
|
|||||||
return NULL;
|
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)
|
char *strstr(const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user