-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
33 lines (30 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kpetrosy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/27 18:38:48 by kpetrosy #+# #+# */
/* Updated: 2021/01/28 18:59:00 by kpetrosy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int idx;
int idx_join;
char *join;
if (!s1 || !s2 || !(join = malloc(sizeof(char) *
(ft_strlen((char *)s1) + ft_strlen((char *)s2) + 1))))
return (NULL);
idx = 0;
idx_join = 0;
while (s1[idx])
join[idx_join++] = s1[idx++];
idx = 0;
while (s2[idx])
join[idx_join++] = s2[idx++];
join[idx_join] = '\0';
return (join);
}