42_libft/ft_memchr.c
Camille Chauvet 1d0f0b1901 m
2022-09-27 16:29:23 +02:00

32 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 13:40:09 by cchauvet #+# #+# */
/* Updated: 2022/09/27 13:59:03 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *tab;
size_t i;
unsigned char tofind;
tab = (unsigned char *) s;
tofind = (unsigned char) c;
i = 0;
while (i < n)
{
if (tab[i] == tofind)
return (tab + i);
i++;
}
return (NULL);
}