/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: whaffman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/07 14:39:41 by whaffman #+# #+# */ /* Updated: 2024/06/18 16:26:53 by whaffman ### ########.fr */ /* */ /* ************************************************************************** */ #include #include int ft_strncmp(char *s1, char *s2, unsigned int n) { unsigned int i; i = 0; // if (n == 0) // return (0); while (*s1 && *s1 == *s2 && i < n - 1) { s1++; s2++; i++; } return (*s1 - *s2); } #ifdef DEBUG void test(char *s1, char *s2, unsigned int n) { printf("s1: \"%s\"\ns2: \"%s\"\nstrncmp: %d\nft_strncmp: %d\n\n", \ s1, s2, strncmp(s1, s2, n), ft_strncmp(s1, s2, n)); } int main(void) { test("abc", "abc", 3); test("ab", "abc", 3); test("abc", "ab", 3); test("abd", "abc", 3); test("abd", "abc", 2); test("abd", "zbc", 0); test("abd", "zbc", 1); return (0); } #endif