ft_memchr: initial implementation
This commit is contained in:
parent
b176bdaebe
commit
aad909fe23
3 changed files with 59 additions and 2 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||||
# Updated: 2024/10/16 13:22:00 by kcolin ### ########.fr #
|
# Updated: 2024/10/16 13:50:09 by kcolin ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -28,7 +28,8 @@ SOURCES = ft_isalpha.c \
|
||||||
ft_tolower.c \
|
ft_tolower.c \
|
||||||
ft_strchr.c \
|
ft_strchr.c \
|
||||||
ft_strrchr.c \
|
ft_strrchr.c \
|
||||||
ft_strncmp.c
|
ft_strncmp.c \
|
||||||
|
ft_memchr.c
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
OBJECTS = $(SOURCES:.c=.o)
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
|
|
|
||||||
54
ft_memchr.c
Normal file
54
ft_memchr.c
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/10/16 14:01:28 by kcolin #+# #+# */
|
||||||
|
/* Updated: 2024/10/16 14:05:38 by kcolin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, t_size n)
|
||||||
|
{
|
||||||
|
t_size i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
if (((const unsigned char *)s)[i] == (unsigned char)c)
|
||||||
|
return ((void *)s + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
t_size cmp_len;
|
||||||
|
|
||||||
|
cmp_len = 5;
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
result = ft_memchr(argv[1], argv[2][0], cmp_len);
|
||||||
|
if (result == 0)
|
||||||
|
printf("(null)\n");
|
||||||
|
else
|
||||||
|
printf("%s\n", result);
|
||||||
|
result = memchr(argv[1], argv[2][0], cmp_len);
|
||||||
|
if (result == 0)
|
||||||
|
printf("(null)\n");
|
||||||
|
else
|
||||||
|
printf("%s\n", result);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*/
|
||||||
2
libft.h
2
libft.h
|
|
@ -37,4 +37,6 @@ char *ft_strchr(const char *s, int c);
|
||||||
char *ft_strrchr(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);
|
int ft_strncmp(const char *s1, const char *s2, t_size n);
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, t_size n);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue