42-archive/libftasm/src/str/ft_strdup.c

31 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:01 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *dup;
int size;
int i;
i = 0;
size = ft_strlen(s1);
dup = (char*)malloc(sizeof(*dup) * (size + 1));
while (s1[i] != '\0')
{
dup[i] = s1[i];
i++;
}
dup[i] = '\0';
return (dup);
}