diff --git a/Makefile b/Makefile index 9297378..35569a4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/04 10:51:59 by tmaze #+# #+# # -# Updated: 2018/04/04 15:08:39 by tmaze ### ########.fr # +# Updated: 2018/04/04 15:30:28 by tmaze ### ########.fr # # # #******************************************************************************# @@ -18,6 +18,7 @@ NAME = libft.a SRCS = \ ft_strlen.c \ + ft_strdup.c \ ft_isalpha.c \ ft_isdigit.c \ ft_isalnum.c \ diff --git a/ft_strdup.c b/ft_strdup.c new file mode 100644 index 0000000..1c216dc --- /dev/null +++ b/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaze +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/04/03 16:33:35 by tmaze #+# #+# */ +/* Updated: 2018/04/04 15:29:36 by tmaze ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s1) +{ + int i; + char *ret; + + i = 0; + while (s1[i]) + i++; + if ((ret = (char*)malloc(sizeof(char) * (i + 1))) != NULL) + { + ret[i] = '\0'; + i = -1; + while (s1[++i]) + ret[i] = s1[i]; + } + return (ret); +} diff --git a/libft.h b/libft.h index 7be4580..bfcea1e 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */ -/* Updated: 2018/04/04 10:44:30 by tmaze ### ########.fr */ +/* Updated: 2018/04/04 15:30:00 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define LIBFT_H # include +# include /* ** fonctions obligatoires