diff --git a/Makefile b/Makefile index 6e0274e..4ff2061 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: kcolin +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/14 13:43:59 by kcolin #+# #+# # -# Updated: 2024/10/16 10:46:46 by kcolin ### ########.fr # +# Updated: 2024/10/16 13:22:00 by kcolin ### ########.fr # # # # **************************************************************************** # @@ -27,7 +27,8 @@ SOURCES = ft_isalpha.c \ ft_toupper.c \ ft_tolower.c \ ft_strchr.c \ - ft_strrchr.c + ft_strrchr.c \ + ft_strncmp.c OBJECTS = $(SOURCES:.c=.o) CC = gcc diff --git a/ft_strncmp.c b/ft_strncmp.c new file mode 100644 index 0000000..1e292c5 --- /dev/null +++ b/ft_strncmp.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/16 13:23:17 by kcolin #+# #+# */ +/* Updated: 2024/10/16 13:44:38 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, t_size n) +{ + t_size i; + + i = 0; + while (s1[i] != '\0' && s2[i] != 0) + { + if (i >= n) + return (0); + if (s1[i] != s2[i]) + break ; + i++; + } + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} + +/* +#include +#include + +int main(int argc, char **argv) +{ + t_size cmp_len; + + cmp_len = 9; + if (argc > 2) + { + printf("mine: %d\tlib: %d\n", + ft_strncmp(argv[1], argv[2], cmp_len), + strncmp(argv[1], argv[2], cmp_len)); + } + return (0); +} +*/ diff --git a/libft.h b/libft.h index c287d7f..2eb7506 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */ -/* Updated: 2024/10/16 10:34:08 by kcolin ### ########.fr */ +/* Updated: 2024/10/16 13:23:08 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,5 +35,6 @@ int ft_tolower(int c); char *ft_strchr(const char *s, int c); char *ft_strrchr(const char *s, int c); +int ft_strncmp(const char *s1, const char *s2, t_size n); #endif