From fc29371a10bf6cfd93c4e9ccfe9193c1311efc98 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 27 Dec 2019 17:24:35 +0100 Subject: updated libft, better Makefile and .gitignore --- libft/src/ft_memchr.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'libft/src/ft_memchr.c') 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 +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* 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); } -- cgit v1.2.3