-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strndup.c
34 lines (31 loc) · 1.24 KB
/
ft_strndup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_strndup.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: rcabotia <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/10/16 11:29:09 by rcabotia #+# ## ## #+# */
/* Updated: 2018/10/18 00:37:09 by rcabotia ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *s, size_t n)
{
size_t i;
char *dest;
i = 0;
while (s[i] && i < n)
i++;
if (!(dest = (char*)malloc(sizeof(*dest) * (i + 1))))
return (0);
i = 0;
while (s[i] && i < n)
{
dest[i] = s[i];
i++;
}
dest[i] = '\0';
return (dest);
}