diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-27 17:24:35 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-27 17:24:35 +0100 |
commit | fc29371a10bf6cfd93c4e9ccfe9193c1311efc98 (patch) | |
tree | e5e67174f06e99d945fa2631bbd0648e1fafeec1 /libft/src/ft_memchr.c | |
parent | STDIN corrected (diff) | |
download | 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.gz 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.bz2 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.xz 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.zst 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.zip |
updated libft, better Makefile and .gitignore
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); } |