tgrekov-libft
HIVE libft Oct 2023
Loading...
Searching...
No Matches
ft_strjoin.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strjoin.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/10/25 16:26:56 by tgrekov #+# #+# */
9/* Updated: 2023/11/09 20:53:09 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "libft.h"
21
30char *ft_strjoin(char const *s1, char const *s2)
31{
32 size_t s1_len;
33 size_t s2_len;
34 char *s3;
35
36 if (!s1 || !s2)
37 return (0);
38 s1_len = ft_strlen(s1);
39 s2_len = ft_strlen(s2);
40 s3 = malloc(s1_len + s2_len + 1);
41 if (!s3)
42 return (0);
43 ft_memcpy(s3, s1, s1_len);
44 ft_memcpy(s3 + s1_len, s2, s2_len + 1);
45 return (s3);
46}
void * ft_memcpy(void *dst, const void *src, size_t n)
Copies n bytes from byte string src to byte string dst.
Definition ft_memcpy.c:36
char * ft_strjoin(char const *s1, char const *s2)
Allocates enough space for and appends string s2 to string s1 and returns the new string.
Definition ft_strjoin.c:30
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28