mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 01:34:15 +00:00
feat: add ft_strrchr function
also add ft_strchr content
This commit is contained in:
15
ft_strrchr.c
Normal file
15
ft_strrchr.c
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strrchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = ft_strlen(s) - 1;
|
||||||
|
while (i >= 0)
|
||||||
|
{
|
||||||
|
if (s[i] == c)
|
||||||
|
return ((char *)s + i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
12
libft.h
12
libft.h
@@ -104,6 +104,18 @@ int ft_toupper(int c);
|
|||||||
*/
|
*/
|
||||||
int ft_tolower(int c);
|
int ft_tolower(int c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
The ft_strchr() function locates the
|
||||||
|
first occurrence of c (converted to
|
||||||
|
a char) in the string pointed to by s.
|
||||||
|
*/
|
||||||
char *ft_strchr(const char *s, int c);
|
char *ft_strchr(const char *s, int c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
The strrchr() function is identical
|
||||||
|
to strchr() except it locates the
|
||||||
|
last occurrence of c.
|
||||||
|
*/
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user