-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
41 lines (38 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin.c :+: :+: */
/* +:+ */
/* By: kfu <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/03 14:09:03 by kfu #+# #+# */
/* Updated: 2020/12/02 12:19:42 by kfu ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stddef.h>
char *ft_strjoin(char const *str1, char const *str2)
{
char *tmp;
int i;
int j;
if (!str1 || !str2)
return (NULL);
tmp = (char *)malloc(ft_strlen(str1) + ft_strlen(str2) + 1);
if (!tmp)
return (NULL);
i = 0;
while (str1[i])
{
tmp[i] = str1[i];
i++;
}
j = 0;
while (str2[j])
{
tmp[i + j] = str2[j];
j++;
}
tmp[i + j] = '\0';
return (tmp);
}