42_ft_printf/ft_strdup.c
Camille Chauvet af946dbf97 v1
2022-10-10 19:33:47 +02:00

34 lines
1.1 KiB
C

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