diff options
Diffstat (limited to 'libft/ft_memchr.c')
-rw-r--r-- | libft/ft_memchr.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..13ee6fc --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/09/27 23:53:11 by kdx #+# #+# */ +/* Updated: 2022/10/13 22:32:30 by kdx ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + const unsigned char *data; + unsigned char ch; + size_t i; + + data = s; + ch = c; + i = 0; + while (i < n) + { + if (data[i] == ch) + return ((void *)s + i); + i += 1; + } + return (NULL); +} |