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 #+# #+# */
/* Updated: 2022/09/27 16:07:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *strdup(const char *s)
{
char *in;
char *out;
size_t i;
in = (char *) s;
out = malloc(sizeof(char) * (ft_strlen(in) + 1));
i = 0;
while (in[i])
{
out[i] = in[i];
i++;
}
out[i] = 0;
return (out);
}