From 4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sun, 10 Mar 2024 13:37:45 +0100 Subject: Complete missing functions and add header --- ft_strdup.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ft_strdup.c') diff --git a/ft_strdup.c b/ft_strdup.c index af7ab12..1282c36 100644 --- a/ft_strdup.c +++ b/ft_strdup.c @@ -6,33 +6,38 @@ /* By: dkaiser +#include "libft.h" char *ft_strdup(const char *s1) { char *result; int len; + int i; len = 0; - while (*(s1++)) + while (s1[len]) len++; result = malloc(len + 1); if (!result) return (0); - result[++len] = '\0'; - while (len--) - result[len] = *(--s1); + result[len] = '\0'; + i = 0; + while (i < len) + { + result[i] = s1[i]; + i++; + } return (result); } /* #include */ /* int main() { */ /* char *output; */ -/* char input[] = "Dies ist ein Test."; */ +/* char input[] = "test"; */ /* output = ft_strdup(input); */ /* printf("%s\n", output); */ /* } */ -- cgit v1.2.3