diff options
Diffstat (limited to 'libft/src/ft_memchr.c')
-rw-r--r-- | libft/src/ft_memchr.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libft/src/ft_memchr.c b/libft/src/ft_memchr.c index c2578aa..8dfb477 100644 --- a/libft/src/ft_memchr.c +++ b/libft/src/ft_memchr.c @@ -6,7 +6,7 @@ /* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2019/10/08 19:14:54 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:40:23 by rbousset ### #+. /#+ ###.fr */ +/* Updated: 2019/12/10 18:34:21 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ @@ -17,17 +17,16 @@ void *ft_memchr(const void *s, int c, size_t n) { unsigned char *s_ptr; - size_t i; + unsigned char c_char; - if (!s) - return (NULL); - i = 0; s_ptr = (unsigned char*)s; - while (i < n) + c_char = (unsigned char)c; + while (n > 0) { - if (s_ptr[i] == (unsigned char)c) - return ((char*)&s[i]); - i++; + if (*s_ptr == c_char) + return ((void*)s_ptr); + s_ptr++; + n--; } return (NULL); } |