-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
37 lines (34 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aerrajiy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 12:55:34 by aerrajiy #+# #+# */
/* Updated: 2022/10/16 17:49:32 by aerrajiy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int len;
int i;
int s;
char *joined;
if (!s1 || !s2)
return (NULL);
s = 0;
i = 0;
len = ft_strlen((char *)s1) + ft_strlen((char *)s2);
joined = malloc((len + 1) * sizeof(char));
if (joined == NULL)
return (NULL);
while (((char *)s1)[i] != '\0')
joined[s++] = ((char *)s1)[i++];
i = 0;
while (((char *)s2)[i] != '\0')
joined[s++] = ((char *)s2)[i++];
joined[s] = '\0';
return (joined);
}