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:
parent
d517a05f90
commit
6f22d1eb36
1 changed files with 4 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
i = ft_strlen(s);
|
||||
if (c == '\0')
|
||||
return ((char *)s + i);
|
||||
while (i != 0)
|
||||
{
|
||||
i--;
|
||||
if (s[i] == c)
|
||||
if (s[i] == (unsigned char)c)
|
||||
return ((char *)s + i);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue