-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
49 lines (44 loc) · 1.31 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
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agras <agras@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/26 17:49:30 by agras #+# #+# */
/* Updated: 2021/12/13 17:10:56 by agras ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
static int ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
char *cat;
i = 0;
if (!s1)
return (NULL);
cat = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!cat)
return (NULL);
while (s1[i])
{
cat[i] = s1[i];
i++;
}
while (*s2)
{
cat[i] = *s2;
s2++;
i++;
}
cat[i] = '\0';
return (cat);
}