/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/23 17:03:07 by bchanot #+# #+# */ /* Updated: 2018/10/29 11:56:43 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_strncmp(const char *const s1, const char *const s2, size_t n) { size_t i; i = 0; if ((!s1 && !s2) || (!ft_strlen(s1) && !ft_strlen(s2))) return (false); if ((!s1 && s2) || (s1 && !s2) || (!ft_strlen(s1) && ft_strlen(s2)) || (ft_strlen(s1) && !ft_strlen(s2))) return (true); while (s1[i] == s2[i] && s1[i] && s2[i] && i < n) i++; if (i == n) return (false); return ((unsigned char)s1[i] - (unsigned char)s2[i]); }