-
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: pmaryjo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/05 18:41:56 by pmaryjo #+# #+# */
/* Updated: 2021/09/05 18:41:57 by pmaryjo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int counter;
char *result;
size_t s1_size;
size_t s2_size;
if (!s1 || !s2)
return (NULL);
s1_size = ft_strlen(s1);
s2_size = ft_strlen(s2);
result = (char *)malloc(s1_size + s2_size + 1);
if (!result)
{
return (NULL);
}
counter = 0;
while (*s1)
{
result[counter++] = *s1++;
}
while (*s2)
{
result[counter++] = *s2++;
}
result[counter] = '\0';
return (result);
}