libft
Loading...
Searching...
No Matches
ft_strjoin.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strjoin.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tspoof <tspoof@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2022/11/03 17:39:07 by tspoof #+# #+# */
9/* Updated: 2022/11/21 16:56:06 by tspoof ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15char *ft_strjoin(char const *s1, char const *s2)
16{
17 char *str;
18 size_t s1_len;
19 size_t s2_len;
20
21 if (!s1 || !s2)
22 return (NULL);
23 s1_len = ft_strlen((char *)s1);
24 s2_len = ft_strlen((char *)s2);
25 str = (char *)malloc(sizeof(char) * (s1_len + s2_len + 1));
26 if (!str)
27 return (NULL);
28 ft_strlcpy(str, s1, s1_len + 1);
29 ft_strlcpy(str + s1_len, s2, s2_len + 1);
30 str[s1_len + s2_len] = '\0';
31 return (str);
32}
char * ft_strjoin(char const *s1, char const *s2)
Joins two strings together.
Definition ft_strjoin.c:15
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
Copies string to destination.
Definition ft_strlcpy.c:15
size_t ft_strlen(const char *s)
Length of the string.
Definition ft_strlen.c:15