From e3b830202fd403f47e1c4f4c9f701ac849d031b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Sat, 11 Oct 2025 22:39:55 +0200 Subject: [PATCH] feat: add atoi function --- ft_atoi.c | 23 +++++++++++++++++++++++ ft_memcmp.c | 10 ++++++++++ libft.h | 10 +++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 ft_atoi.c create mode 100644 ft_memcmp.c diff --git a/ft_atoi.c b/ft_atoi.c new file mode 100644 index 0000000..4a2e845 --- /dev/null +++ b/ft_atoi.c @@ -0,0 +1,23 @@ +#include "libft.h" + +int ft_atoi(const char *str) +{ + int value; + size_t len; + size_t i; + int n; + + value = 0; + len = ft_strlen(str); + i = 0; + while (i < len) + { + if (!ft_isdigit(str[i])) + return (value); + n = (int)(str[i] - '0'); + value *= 10; + value += n; + i++; + } + return (value); +} diff --git a/ft_memcmp.c b/ft_memcmp.c new file mode 100644 index 0000000..3dea5f1 --- /dev/null +++ b/ft_memcmp.c @@ -0,0 +1,10 @@ +#include "libft.h" + +// int ft_memcmp(const void *s1, const void *s2, size_t n) +// { +// const unsigned char *s1_ptr; +// const unsigned char *s2_ptr; +// size_t i; + +// while () +// } diff --git a/libft.h b/libft.h index 31b7d99..8f5c24a 100644 --- a/libft.h +++ b/libft.h @@ -2,7 +2,7 @@ #define LIBFT_A #include -# include +#include /* The ft_isalpha() function tests for @@ -129,4 +129,12 @@ int ft_strncmp(const char *s1, const char *s2, size_t n); */ void *ft_memchr(const void *s, int c, size_t n); +// TODO +int ft_memcmp(const void *s1, const void *s2, size_t n); + +// TODO +char *ft_strnstr(const char *haystack, const char *needle, size_t len); + +int ft_atoi(const char *str); + #endif