-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
42 lines (39 loc) · 1.29 KB
/
ft_strjoin.c
File metadata and controls
42 lines (39 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin.c :+: :+: */
/* +:+ */
/* By: nsterk <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/09/22 15:39:01 by nsterk #+# #+# */
/* Updated: 2021/03/03 01:42:08 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
size_t i;
char *str;
if (!s1 || !s2)
return (NULL);
len = ft_strlen((char *)s1) + ft_strlen((char *)s2);
str = (char *)malloc(sizeof(*str) * (len + 1));
if (!str)
return (NULL);
i = 0;
while (*s1 != '\0')
{
str[i] = *s1;
i++;
s1++;
}
while (*s2 != '\0')
{
str[i] = *s2;
i++;
s2++;
}
str[i] = '\0';
return (str);
}