From c25260933d91a015ea2100a793a0f7a37f9a7405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Wed, 8 Oct 2025 10:31:48 +0200 Subject: [PATCH] feat: add ft_strrchr function also add ft_strchr content --- ft_strrchr.c | 15 +++++++++++++++ libft.h | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ft_strrchr.c diff --git a/ft_strrchr.c b/ft_strrchr.c new file mode 100644 index 0000000..29ecc7e --- /dev/null +++ b/ft_strrchr.c @@ -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); +} diff --git a/libft.h b/libft.h index 68fe8ac..66f0b1b 100644 --- a/libft.h +++ b/libft.h @@ -104,6 +104,18 @@ int ft_toupper(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); +/* + The strrchr() function is identical + to strchr() except it locates the + last occurrence of c. +*/ +char *ft_strrchr(const char *s, int c); + #endif