42_ft_printf/ft_strdup.c

34 lines
1.1 KiB
C
Raw Normal View History

2022-10-06 20:30:03 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
2022-10-10 13:33:47 -04:00
/* Updated: 2022/10/10 18:48:37 by cchauvet ### ########.fr */
2022-10-06 20:30:03 -04:00
/* */
/* ************************************************************************** */
2022-10-10 13:33:47 -04:00
#include "printf.h"
2022-10-06 20:30:03 -04:00
2022-10-10 13:33:47 -04:00
char *ft_strdup(const char *s)
2022-10-06 20:30:03 -04:00
{
char *out;
size_t i;
2022-10-10 13:33:47 -04:00
if (s == NULL)
return (NULL);
2022-10-06 20:30:03 -04:00
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);
}