/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strdup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 13:56:54 by hulamy #+# #+# */ /* Updated: 2022/05/04 14:05:57 by pblagoje ### ########.fr */ /* */ /* ************************************************************************** */ /* ** save a copy of string src by allocating memory and return pointer to copy */ #include "libft.h" char *ft_strdup(const char *src) { int i; char *str; i = 0; while (src[i] != '\0') i++; str = (char *)malloc(sizeof(*str) * (i + 1)); if (!str) return (NULL); while (i-- >= 0) str[i + 1] = src[i + 1]; return (str); }