42_libft/ft_memchr.c

32 lines
1.1 KiB
C
Raw Permalink Normal View History

2022-09-27 10:29:23 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}