ft_memcmp.c 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_memcmp.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/11/24 18:26:36 by mazimi #+# #+# */
  9. /* Updated: 2014/12/02 15:56:02 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. int ft_memcmp(const void *s1, const void *s2, size_t n)
  14. {
  15. size_t i;
  16. unsigned char *str1;
  17. unsigned char *str2;
  18. if (s1 == NULL || s2 == NULL)
  19. return (0);
  20. str1 = (unsigned char *)s1;
  21. str2 = (unsigned char *)s2;
  22. i = -1;
  23. while (++i < n)
  24. if (str1[i] != str2[i])
  25. return (str1[i] - str2[i]);
  26. return (0);
  27. }