1
0

memchr & memcmp finish

This commit is contained in:
Adam Joly
2023-11-08 12:46:30 +01:00
parent dcd1874c67
commit 822a2af613
4 changed files with 22 additions and 16 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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)

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -6,17 +6,17 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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])
{
// }
// }
}
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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