ft_memchr.c 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_memchr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2015/11/24 19:06:29 by bchanot #+# #+# */
  9. /* Updated: 2018/10/29 12:19:47 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. void *ft_memchr(const void *s, int c, size_t n)
  14. {
  15. unsigned char *str;
  16. size_t cpt;
  17. cpt = 0;
  18. if (s && n)
  19. {
  20. str = (unsigned char *)s;
  21. while (cpt < n)
  22. {
  23. if (*str == (unsigned char)c)
  24. return ((void *)str);
  25. cpt++;
  26. str++;
  27. }
  28. }
  29. return (NULL);
  30. }