diff --git a/Makefile b/Makefile index c99db96..2ce252a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: kcolin +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/14 13:43:59 by kcolin #+# #+# # -# Updated: 2024/10/16 13:50:09 by kcolin ### ########.fr # +# Updated: 2024/10/16 15:22:08 by kcolin ### ########.fr # # # # **************************************************************************** # @@ -29,7 +29,8 @@ SOURCES = ft_isalpha.c \ ft_strchr.c \ ft_strrchr.c \ ft_strncmp.c \ - ft_memchr.c + ft_memchr.c \ + ft_memcmp.c OBJECTS = $(SOURCES:.c=.o) CC = gcc diff --git a/ft_memcmp.c b/ft_memcmp.c new file mode 100644 index 0000000..da7e26a --- /dev/null +++ b/ft_memcmp.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/16 15:26:08 by kcolin #+# #+# */ +/* Updated: 2024/10/16 15:31:27 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + + i = 0; + while (1) + { + if (i >= n) + return (0); + if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i]) + break ; + i++; + } + return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); +} + +/* +#include +#include + +int main(int argc, char **argv) +{ + size_t cmp_len; + + cmp_len = 0; + if (argc > 2) + { + printf("mine: %d\tlib: %d\n", + ft_memcmp(argv[1], argv[2], cmp_len), + memcmp(argv[1], argv[2], cmp_len)); + } + return (0); +} +*/ diff --git a/ft_strncmp.c b/ft_strncmp.c index 6e2b3fc..d17e645 100644 --- a/ft_strncmp.c +++ b/ft_strncmp.c @@ -17,7 +17,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n) size_t i; i = 0; - while (s1[i] != '\0' && s2[i] != 0) + while (s1[i] != '\0' && s2[i] != '\0') { if (i >= n) return (0); diff --git a/libft.h b/libft.h index d47fe2b..ea82cf6 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 15:16:50 by kcolin ### ########.fr */ +/* Updated: 2024/10/16 15:25:46 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,5 +38,6 @@ char *ft_strrchr(const char *s, int c); int ft_strncmp(const char *s1, const char *s2, size_t n); void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); #endif