libft/ft_strdup.c
2018-04-04 15:50:08 +02:00

32 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}