-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
42 lines (39 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tedison <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/02 14:11:25 by tedison #+# #+# */
/* Updated: 2021/04/03 17:44:29 by tedison ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *final;
int s1_l;
int s2_l;
int i;
int j;
if (s1 == 0 || s2 == 0)
return (NULL);
s1_l = ft_strlen(s1);
s2_l = ft_strlen(s2);
i = 0;
j = 0;
final = malloc(sizeof(*final) * (s1_l + s2_l + 1));
if (!final)
return (NULL);
while (i < (s1_l + s2_l))
{
if (i < s1_l)
final[i] = s1[i];
else
final[i] = s2[j++];
i++;
}
final[i] = '\0';
return (final);
}