-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
45 lines (40 loc) · 1.42 KB
/
ft_strjoin.c
File metadata and controls
45 lines (40 loc) · 1.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mattig <mattig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/28 17:17:05 by mattig #+# #+# */
/* Updated: 2021/11/04 18:48:29 by mattig ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
static char *ft_strcat(char *dst, const char *src)
{
char *d;
d = dst;
while (*d)
d++;
while (*src)
*d++ = *src++;
*d = '\0';
return (dst);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int len_s1;
int len_s2;
char *ptr_s;
if (!s1 || !s2)
return (NULL);
len_s2 = ft_strlen(s2);
len_s1 = ft_strlen(s1);
ptr_s = (char *)malloc(sizeof(char) * (len_s1 + len_s2) + 1);
if (ptr_s == NULL)
return (NULL);
ft_strlcpy(ptr_s, s1, (ft_strlen(s1) + 1));
ft_strcat(ptr_s, s2);
return (ptr_s);
}