diff --git a/Makefile b/Makefile index 058cdc3..97a46ba 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# # -# Updated: 2023/11/06 17:37:53 by adjoly ### ########.fr # +# Updated: 2023/11/08 12:14:33 by adjoly ### ########.fr # # # # **************************************************************************** # @@ -39,6 +39,8 @@ SRCS = ft_atoi.c \ ft_strchr.c \ ft_itoa.c \ ft_calloc.c \ + ft_memchr.c \ + ft_memcmp.c \ OBJS = $(SRCS:.c=.o) @@ -49,7 +51,7 @@ HEADER = libft.h $(NAME): $(OBJS) ar -rcs $(NAME) $(OBJS) -# so: +so: $(CC) -nostartfiles -fPIC $(CFLAGS) $(SRCS) gcc -nostartfiles -shared -o libft.so $(OBJS) diff --git a/ft_memchr.c b/ft_memchr.c index 927d102..3483542 100644 --- a/ft_memchr.c +++ b/ft_memchr.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/05 14:52:53 by adjoly #+# #+# */ -/* Updated: 2023/11/06 15:37:15 by adjoly ### ########.fr */ +/* Updated: 2023/11/08 11:59:58 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,16 @@ void *ft_memchr(const void *s, int c, size_t n) { - int i; + size_t i; i = 0; - while (i < n && ((unsigned char *)s)[i] && ((char *)s) != c) + while (((char *)s)[i] && i < n) { - s++; + if (((char *)s)[i] == (char)c) + return (((char *)s + i)); i++; } + if (c == 0) + return (((char *)s) + i); return (NULL); } diff --git a/ft_strchr.c b/ft_strchr.c index b73da82..4d96690 100644 --- a/ft_strchr.c +++ b/ft_strchr.c @@ -6,17 +6,17 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/01 15:45:18 by adjoly #+# #+# */ -/* Updated: 2023/11/05 21:33:16 by adjoly ### ########.fr */ +/* Updated: 2023/11/08 12:17:21 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ -// char *ft_strchr(const char *s, int c) -// { - // int i; +char *ft_strchr(const char *s, int c) +{ + int i; - // i = 0; - // while (s[i]) - // { + i = 0; + while (s[i]) + { - // } -// } + } +} diff --git a/libft.h b/libft.h index d402f9a..ad81796 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */ -/* Updated: 2023/11/06 11:03:52 by adjoly ### ########.fr */ +/* Updated: 2023/11/08 12:14:58 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,5 +45,6 @@ void *ft_memchr(const void *s, int c, size_t n); char *ft_itoa(int n); void *ft_memmove(void *dest, const void *src, 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 \ No newline at end of file