-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
40 lines (37 loc) · 1.3 KB
/
Copy pathft_strjoin.c
File metadata and controls
40 lines (37 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin.c :+: :+: */
/* +:+ */
/* By: rvan-sch <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/22 20:55:45 by rvan-sch #+# #+# */
/* Updated: 2019/11/22 20:55:46 by rvan-sch ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
size_t i;
size_t len1;
size_t len2;
if (s1 == 0 || s2 == 0)
return (0);
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
str = (char *)malloc((len1 + len2) * sizeof(char) + 1);
if (str == 0)
return (0);
i = 0;
while (i < len1 + len2)
{
if (i < len1)
str[i] = s1[i];
else
str[i] = s2[i - len1];
i++;
}
str[i] = '\0';
return (str);
}