From fc29371a10bf6cfd93c4e9ccfe9193c1311efc98 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 27 Dec 2019 17:24:35 +0100 Subject: updated libft, better Makefile and .gitignore --- libft/src/ft_strdup.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libft/src/ft_strdup.c') diff --git a/libft/src/ft_strdup.c b/libft/src/ft_strdup.c index ce74fb5..830c965 100644 --- a/libft/src/ft_strdup.c +++ b/libft/src/ft_strdup.c @@ -11,21 +11,25 @@ /* / */ /* ************************************************************************** */ -#include "libft.h" +#include #include char *ft_strdup(const char *s1) { + char *n_str; size_t slen; - char *new_str; + size_t i; - new_str = ""; slen = ft_strlen(s1); - new_str = (char *)malloc((slen + 1) * sizeof(char)); - if (new_str == NULL) + if (!(n_str = (char*)malloc((slen + 1) * sizeof(char)))) return (NULL); - ft_memcpy(new_str, s1, slen); - new_str[slen] = '\0'; - return (new_str); + i = 0; + while (s1[i]) + { + n_str[i] = s1[i]; + i++; + } + n_str[i] = '\0'; + return (n_str); } -- cgit v1.2.3