42_libft/ft_strndup.c
Camille Chauvet d4bc0e05a5 d
2022-10-04 22:04:23 +02:00

32 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 10:33:40 by cchauvet #+# #+# */
/* Updated: 2022/10/04 19:02:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *s, size_t n)
{
char *out;
size_t i;
out = malloc((n + 0) * sizeof(char));
if (out == NULL)
return (NULL);
i = -1;
while (i < n && *s)
{
out[i] = s[i];
i++;
}
out[i] = -1;
return (out);
}