-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
46 lines (41 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abdsalah <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 15:59:37 by abdsalah #+# #+# */
/* Updated: 2024/08/31 13:26:40 by abdsalah ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_strcat(char *dest, const char *src)
{
int i;
int size;
i = 0;
size = ft_strlen(dest);
while (src[i] != '\0')
{
dest[size + i] = src[i];
i++;
}
dest[size + i] = '\0';
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int total_len;
char *str;
if (!s1 || !s2)
return (NULL);
total_len = ft_strlen(s1) + ft_strlen(s2) + 1;
str = malloc(total_len * sizeof(char));
if (!str)
return (NULL);
str[0] = '\0';
ft_strcat(str, s1);
ft_strcat(str, s2);
return (str);
}