42_libft/ft_strdup.c

32 lines
1.1 KiB
C
Raw Permalink Normal View History

2022-09-27 10:29:23 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
2022-10-05 15:04:45 -04:00
/* Updated: 2022/10/04 23:24:11 by cchauvet ### ########.fr */
2022-09-27 10:29:23 -04:00
/* */
/* ************************************************************************** */
#include "libft.h"
2022-10-04 08:21:55 -04:00
char *ft_strdup(const char *s)
2022-09-27 10:29:23 -04:00
{
char *out;
size_t i;
2022-10-05 15:04:45 -04:00
out = ft_calloc((ft_strlen(s) + 1), sizeof(char));
2022-10-04 08:21:55 -04:00
if (out == NULL)
return (NULL);
2022-09-27 10:29:23 -04:00
i = 0;
2022-10-04 08:21:55 -04:00
while (s[i])
2022-09-27 10:29:23 -04:00
{
2022-10-04 08:21:55 -04:00
out[i] = s[i];
2022-09-27 10:29:23 -04:00
i++;
}
out[i] = 0;
return (out);
}