ft_memcmp.c 1.2 KB

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