-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strnjoin.c
35 lines (32 loc) · 1.26 KB
/
ft_strnjoin.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vbrazas <vbrazas@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/02 20:01:16 by vbrazas #+# #+# */
/* Updated: 2018/03/02 20:07:30 by vbrazas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnjoin(char const *s1, char const *s2, size_t l1, size_t l2)
{
char *buf;
size_t i;
size_t j;
if (s1 == NULL || s2 == NULL)
return (NULL);
buf = (char *)malloc(sizeof(*buf) * (l1 + l2 + 1));
if (buf == NULL)
return (NULL);
i = 0;
j = 0;
while (i < l1)
buf[i++] = s1[j++];
j = 0;
while (j < l2)
buf[i++] = s2[j++];
buf[i] = '\0';
return (buf);
}