Projet de l'école 42 : Libft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
1.1 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/19 14:07:50 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_strdup(const char *src)
{
char *dup;
size_t i;
i = 0;
dup = malloc((ft_strlen(src) + 1) * sizeof(char));
if (!dup)
return (NULL);
while (src[i])
{
dup[i] = src[i];
i++;
}
dup[i] = '\0';
return (dup);
}