From 05cf4aa285684e572489051cee01f2f2a2e7c17a Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Tue, 28 Mar 2023 18:55:18 +0200 Subject: [PATCH] Exception for n==0 --- ex01/ft_strncmp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ex01/ft_strncmp.c b/ex01/ft_strncmp.c index b2281a6..afa4834 100644 --- a/ex01/ft_strncmp.c +++ b/ex01/ft_strncmp.c @@ -6,12 +6,14 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/24 02:01:33 by tischmid #+# #+# */ -/* Updated: 2023/03/28 05:02:15 by tischmid ### ########.fr */ +/* Updated: 2023/03/28 18:54:54 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strncmp(char *s1, char *s2, unsigned int n) { + if (!n) + return (1); while (*s1 && *s2 && *s1 == *s2 && --n) { ++s1; @@ -24,7 +26,7 @@ int ft_strncmp(char *s1, char *s2, unsigned int n) #include #define STR1 "abd" #define STR2 "abc" -#define LENGTH 3 +#define LENGTH 0 int main(void) {