-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
55 lines (49 loc) · 1.54 KB
/
ft_strjoin.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebassi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/11 17:05:13 by ebassi #+# #+# */
/* Updated: 2022/01/12 15:57:46 by ebassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_res(char const *s1, char const *s2, char *res, int len);
char *ft_strjoin(char const *s1, char const *s2)
{
char *res;
int len;
len = (int)ft_strlen(s1) + (int)ft_strlen(s2);
res = (char *) malloc (len + 1);
if (!res)
return (NULL);
ft_res(s1, s2, res, len);
return (res);
}
static char *ft_res(char const *s1, char const *s2, char *res, int len)
{
int index;
int j;
index = 0;
j = 0;
while (index < len)
{
while (j < (int)ft_strlen(s1))
{
res[index] = s1[j];
index++;
j++;
}
j = 0;
while (j < (int)ft_strlen(s2))
{
res[index] = s2[j];
index++;
j++;
}
}
res[index] = '\0';
return (res);
}