From f4238872bb85d8317f5b4867b45cf81197ba0576 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Thu, 14 Mar 2024 12:07:14 +0100 Subject: [PATCH] feat(ft_strncmp) --- .gitignore | 2 ++ Makefile | 1 + inc/libft.h | 1 + src/ft_strncmp.c | 10 ++++++++++ 4 files changed, 14 insertions(+) create mode 100644 src/ft_strncmp.c diff --git a/.gitignore b/.gitignore index 40f8930..d109ca9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +main.c + # vim *.swp diff --git a/Makefile b/Makefile index f7fe466..5e772e6 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ NAME = libft.a SRC_FILES = ft_strdup.c \ ft_strlen.c \ + ft_strncmp.c \ INC_FILES = libft.h \ diff --git a/inc/libft.h b/inc/libft.h index ceb21cb..f6f5a24 100644 --- a/inc/libft.h +++ b/inc/libft.h @@ -6,5 +6,6 @@ char *ft_strdup(const char *s); size_t ft_strlen(const char *s); +int ft_strncmp(const char *s1, const char *s2, size_t n); #endif diff --git a/src/ft_strncmp.c b/src/ft_strncmp.c new file mode 100644 index 0000000..6797643 --- /dev/null +++ b/src/ft_strncmp.c @@ -0,0 +1,10 @@ +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) { + for (size_t i = 0; i < n; i++) { + if (!s1[i] || s1[i] != s2[i]) { + return s1[i] - s2[i]; + } + } + return 0; +}