-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
54 lines (49 loc) · 1.56 KB
/
ft_strjoin.c
File metadata and controls
54 lines (49 loc) · 1.56 KB
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
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ghuertas <ghuertas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/26 18:11:56 by dolvin17 #+# #+# */
/* Updated: 2023/09/28 19:27:32 by ghuertas ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
/* reserva con malloc un nuevo string, basado en la union
de los dos strings dados como parámetros */
static size_t ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strjoin(char const *str_1, char const *str_2)
{
size_t len;
char *sum_str;
size_t i;
size_t j;
if (!str_1 || !str_2)
return (NULL);
len = ft_strlen(str_1) + ft_strlen(str_2) + 1;
sum_str = malloc(sizeof(char) * len + 1);
if (!sum_str)
return (NULL);
i = 0;
while (i < ft_strlen(str_1))
{
sum_str[i] = str_1[i];
i++;
}
j = 0;
while (j < ft_strlen(str_2))
{
sum_str[i + j] = str_2[j];
j++;
}
sum_str[i + j] = '\0';
return (sum_str);
}