From 8ad0f35891994a79e6e2586b5f083abcce0e5981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=ABy=20Noort?= Date: Mon, 5 May 2025 19:14:45 +0200 Subject: [PATCH] feat: added ft_strcmp.c --- hdrs/libft.h | 1 + srcs/ft_strcmp.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 srcs/ft_strcmp.c diff --git a/hdrs/libft.h b/hdrs/libft.h index 79effd4..8b65d36 100644 --- a/hdrs/libft.h +++ b/hdrs/libft.h @@ -3,6 +3,7 @@ # include +int ft_strcmp(const char *s1, const char *s2); int ft_islower(int c); int ft_isupper(int c); int ft_tolower(int c); diff --git a/srcs/ft_strcmp.c b/srcs/ft_strcmp.c new file mode 100644 index 0000000..333207b --- /dev/null +++ b/srcs/ft_strcmp.c @@ -0,0 +1,12 @@ +#include + +int ft_strcmp(const char *s1, const char *s2) +{ + while (*s1 && (*s1 == *s2)) // Continue while both are equal and non-null + { + s1++; + s2++; + } + + return (unsigned char)(*s1) - (unsigned char)(*s2); // Return the difference of the first non-matching characters +} \ No newline at end of file