42_libft/ft_strdup.c
Camille Chauvet be438f7dec v2
2022-10-04 14:21:55 +02:00

32 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
/* Updated: 2022/09/29 11:03:42 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *out;
size_t i;
out = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (out == NULL)
return (NULL);
i = 0;
while (s[i])
{
out[i] = s[i];
i++;
}
out[i] = 0;
return (out);
}