/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */ /* Updated: 2025/09/01 17:54:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include /** * @brief Compares two strings up to a specified number of characters. * * @param s1 The first string to compare. * @param s2 The second string to compare. * @param n The maximum number of characters to compare. * * @return An integer indicating the relationship between the two strings. */ int ft_strncmp(const char *s1, const char *s2, size_t n) { size_t i; int diff; i = 0; while ((s1[i] || s2[i]) && i < n) { if (s1[i] != s2[i]) { diff = (unsigned char)s1[i] - (unsigned char)s2[i]; return (diff); } i++; } return (0); }