diff options
Diffstat (limited to 'libft/src/ft_strdup.c')
-rw-r--r-- | libft/src/ft_strdup.c | 20 |
1 files changed, 12 insertions, 8 deletions
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 <libft.h> #include <stdlib.h> 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); } |