From 5b653ccffdc33c8774697a93cad0b499b88dca71 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 28 Jul 2019 21:12:28 +0200 Subject: std library function almost done, tested with libft-unit-tests --- ft_strdup.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ft_strdup.c (limited to 'ft_strdup.c') diff --git a/ft_strdup.c b/ft_strdup.c new file mode 100644 index 0000000..e3609cc --- /dev/null +++ b/ft_strdup.c @@ -0,0 +1,22 @@ +#include +#include "libft.h" + +char *ft_strdup(const char *s) +{ + char *clone; + size_t i; + size_t len; + + len = ft_strlen(s); + if ((clone = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + i = 0; + while (i < len) + { + clone[i] = s[i]; + i++; + } + clone[i] = '\0'; + return (clone); +} + -- cgit