libft
ft_strjoin.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strjoin.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/05 11:53:04 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:45:13 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 
26 char *ft_strjoin(const char *s1, const char *s2)
27 {
28  char *s_joined;
29 
30  if (!s1 && !s2)
31  return (NULL);
32  else if (!s1)
33  return (char *)s2;
34  else if (!s2)
35  return (char *)s1;
36  if (!(s_joined = ft_strnew(ft_strlen(s1) + ft_strlen(s2))))
37  return (NULL);
38  s_joined = ft_strcpy(s_joined, s1);
39  s_joined = ft_strcat(s_joined, s2);
40  return (s_joined);
41 }
ft_strlen
size_t ft_strlen(const char *s)
Replicates behaviour of strlen from libc.
Definition: ft_strlen.c:20
ft_strjoin
char * ft_strjoin(const char *s1, const char *s2)
Joins two strings.
Definition: ft_strjoin.c:26
ft_strcat
char * ft_strcat(char *s1, const char *s2)
Replicates behaviour of strcat from libc.
Definition: ft_strcat.c:20
libft.h
ft_strnew
char * ft_strnew(size_t size)
Allocates a fresh string.
Definition: ft_strnew.c:25
ft_strcpy
char * ft_strcpy(char *dst, const char *src)
Replicates behaviour of strcpy from libc.
Definition: ft_strcpy.c:20