ft_memchr.c 1.1 KB

1234567891011121314151617181920212223242526
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_memchr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/11/12 16:03:22 by mazimi #+# #+# */
  9. /* Updated: 2014/12/02 15:55:54 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. void *ft_memchr(const void *s, int c, size_t n)
  14. {
  15. size_t i;
  16. i = -1;
  17. if (s == NULL)
  18. return (NULL);
  19. while (++i < n)
  20. if (((unsigned char *)s)[i] == (unsigned char)c)
  21. return ((void *)s + i);
  22. return (NULL);
  23. }