-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
44 lines (39 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/24 14:30:19 by jbadaire #+# #+# */
/* Updated: 2022/11/24 14:30:19 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static int ft_fill(void **mlc, char const *text, int mlc_index)
{
int index;
index = 0;
while (text[index])
{
((char *)mlc)[mlc_index] = text[index];
index++;
mlc_index++;
}
return (mlc_index);
}
char *ft_strjoin(char const *s1, char const *s2)
{
void *mlc;
int size;
if (!s1 || !s2)
return (NULL);
mlc = malloc(sizeof(char ) * (ft_strlen(s1) + ft_strlen(s2)) + 1);
if (!mlc)
return (NULL);
size = ft_fill(mlc, s1, 0);
size = ft_fill(mlc, s2, size);
((char *) mlc)[size] = '\0';
return ((char *) mlc);
}