-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
37 lines (34 loc) · 1.51 KB
/
ft_strjoin.c
File metadata and controls
37 lines (34 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/26 18:23:41 by jowagner #+# #+# */
/* Updated: 2024/12/12 19:49:53 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Concatenates two strings into a newly allocated string.
*
* @param s1 The first string to concatenate.
* @param s2 The second string to concatenate.
* @return A pointer to the newly allocated string containing
* the concatenation of s1 and s2, or NULL if the allocation fails.
*/
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len_s1;
size_t len_s2;
char *result;
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
result = malloc(sizeof(char) * (len_s1 + len_s2 + 1));
if (!result)
return (NULL);
ft_strlcpy(result, s1, len_s1 + 1);
ft_strlcat(result + len_s1, s2, len_s2 + 1);
return (result);
}