-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin_ff.c
33 lines (29 loc) · 1.29 KB
/
ft_strjoin_ff.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin_ff.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgaia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/08 18:28:07 by rgaia #+# #+# */
/* Updated: 2017/12/08 18:29:45 by rgaia ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Joins both arguments, returning a fresh allocated joined string.
** EXTRA: 'ff' = frees first string before returning
*/
char *ft_strjoin_ff(char *s1, char const *s2)
{
char *str;
if (s1 == NULL || s2 == NULL)
return (NULL);
str = ft_strnew(ft_strlen(s1) + ft_strlen(s2));
if (str == NULL)
return (NULL);
str = ft_strcpy(str, s1);
str = ft_strcat(str, s2);
ft_strdel(&s1);
return (str);
}