42_solong/libftx/libft/ft_strdup.c

32 lines
1.1 KiB
C
Raw Normal View History

2022-12-22 11:54:17 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
/* Updated: 2022/10/04 23:24:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *out;
size_t i;
out = ft_calloc((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);
}