rt/libft/ft_memchr.c

30 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: scebula <scebula@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 19:51:45 by scebula #+# #+# */
/* Updated: 2015/11/30 01:19:27 by scebula ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *src;
src = (unsigned char*)s;
while (n > 0 && *src != (unsigned char)c)
{
src++;
n--;
}
if (n == 0)
return (NULL);
else
return ((void*)src);
}