32 lines
1.1 KiB
C
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/09/29 11:03:02 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strndup(const char *s, size_t n)
|
|
{
|
|
char *out;
|
|
size_t i;
|
|
|
|
out = malloc((n + 1) * sizeof(char));
|
|
if (out == NULL)
|
|
return (NULL);
|
|
i = 0;
|
|
while (i < n && *s)
|
|
{
|
|
out[i] = s[i];
|
|
i++;
|
|
}
|
|
out[i] = 0;
|
|
return (out);
|
|
}
|