ft_strrchr: fix 2 small bugs

1. Compairing was done with ints, not bytes
2. did not correctly give pointer to null terminator
This commit is contained in:
Khaïs COLIN 2024-10-18 17:47:30 +02:00
parent d517a05f90
commit 6f22d1eb36

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */ /* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */
/* Updated: 2024/10/16 10:48:57 by kcolin ### ########.fr */ /* Updated: 2024/10/18 17:46:26 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,10 +17,12 @@ char *ft_strrchr(const char *s, int c)
int i; int i;
i = ft_strlen(s); i = ft_strlen(s);
if (c == '\0')
return ((char *)s + i);
while (i != 0) while (i != 0)
{ {
i--; i--;
if (s[i] == c) if (s[i] == (unsigned char)c)
return ((char *)s + i); return ((char *)s + i);
} }
return (0); return (0);