33 lines
1.1 KiB
C
33 lines
1.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strdup.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2016/08/08 09:31:51 by jhalford #+# #+# */
|
|
/* Updated: 2016/08/22 13:56:36 by jhalford ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
|
|
char *ft_strdup(char *src)
|
|
{
|
|
char *dup;
|
|
int size;
|
|
int i;
|
|
|
|
i = 0;
|
|
size = 0;
|
|
while (src[size] != '\0')
|
|
size++;
|
|
dup = (char*)malloc(sizeof(*dup) * (size + 1));
|
|
while (src[i] != '\0')
|
|
{
|
|
dup[i] = src[i];
|
|
i++;
|
|
}
|
|
dup[i] = '\0';
|
|
return (dup);
|
|
}
|