-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
36 lines (33 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anpayot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 03:13:57 by anpayot #+# #+# */
/* Updated: 2024/10/17 03:15:21 by anpayot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *joined_str;
char *ptr;
size_t s1_len;
size_t s2_len;
if (!s1 || !s2)
return (NULL);
s1_len = ft_strlen(s1);
s2_len = ft_strlen(s2);
joined_str = (char *)malloc(sizeof(char) * (s1_len + s2_len + 1));
if (!joined_str)
return (NULL);
ptr = joined_str;
while (*s1)
*ptr++ = *s1++;
while (*s2)
*ptr++ = *s2++;
*ptr = '\0';
return (joined_str);
}