From 2a34720f4d83370b8a21634d0329760c6a937aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=ABy=20Noort?= Date: Sat, 31 May 2025 19:37:36 +0200 Subject: [PATCH] feat: added strdup and putptr --- srcs/ft_strdup.c | 19 +++++++++++++++++++ srcs/vec/ft_putrptr.c | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 srcs/ft_strdup.c create mode 100644 srcs/vec/ft_putrptr.c diff --git a/srcs/ft_strdup.c b/srcs/ft_strdup.c new file mode 100644 index 0000000..e18ad3a --- /dev/null +++ b/srcs/ft_strdup.c @@ -0,0 +1,19 @@ +#include "libft.h" +#include + +char *ft_strdup(const char *s) +{ + size_t len = 0; + char *dup; + size_t i; + + while (s[len]) + len++; + dup = (char *)malloc(len + 1); + if (!dup) + return NULL; + for (i = 0; i < len; i++) + dup[i] = s[i]; + dup[len] = '\0'; + return (dup); +} \ No newline at end of file diff --git a/srcs/vec/ft_putrptr.c b/srcs/vec/ft_putrptr.c new file mode 100644 index 0000000..a80ef49 --- /dev/null +++ b/srcs/vec/ft_putrptr.c @@ -0,0 +1,13 @@ +#include "libft.h" + +int ft_putptr(void *ptr) +{ + int count = 0; + + count += ft_putstr("0x"); + if (!ptr) + count += ft_putchar('0'); + else + count += ft_putaddr((unsigned long)ptr); + return (count); +}