ft_strncmp.c 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strncmp.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/11/25 14:13:10 by mazimi #+# #+# */
  9. /* Updated: 2016/09/30 15:24:22 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. int ft_strncmp(const char *s1, const char *s2, size_t n)
  14. {
  15. unsigned char s11;
  16. unsigned char s22;
  17. if (s1 == NULL && s2 == NULL)
  18. return (0);
  19. else if (s1 == NULL || s2 == NULL)
  20. return (-122);
  21. s11 = *s1;
  22. s22 = *s2;
  23. if (!n || (!s11 && !s22))
  24. return (0);
  25. else if (s11 != s22)
  26. return (s11 - s22);
  27. return (ft_strncmp(++s1, ++s2, --n));
  28. }