-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncpy.c
37 lines (34 loc) · 1.21 KB
/
ft_strncpy.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
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lmartine <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/26 21:14:54 by lmartine #+# #+# */
/* Updated: 2018/03/06 23:49:18 by lmartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncpy(char *dst, const char *src, size_t len)
{
size_t i;
char *s1;
char *s2;
i = 0;
s1 = dst;
s2 = (char*)src;
if (ft_strlen(s2) < len)
{
while (i++ < ft_strlen(s2))
*dst++ = *src++;
while (i++ <= len)
*dst++ = '\0';
}
else
{
while (i++ < len && src)
*dst++ = *src++;
}
return (s1);
}