42_libft/ft_strdup.c

32 lines
1.1 KiB
C
Raw 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-04 08:21:55 -04:00
/* Updated: 2022/09/29 11:03:42 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-04 08:21:55 -04:00
out = malloc(sizeof(char) * (ft_strlen(s) + 1));
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);
}