-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strjoin.c
41 lines (37 loc) · 1.31 KB
/
ft_strjoin.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
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: psprawka <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/21 19:34:05 by psprawka #+# #+# */
/* Updated: 2019/09/14 22:54:39 by psprawka ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#define S1 1
#define S2 2
char *ft_strjoin(char *s1, char *s2, bool sfree)
{
char *f;
int i;
int j;
if (!s1 || !s2)
return (NULL);
if (!(f = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
return (NULL);
i = -1;
while (s1[++i])
f[i] = s1[i];
if (sfree & S1)
free(s1);
if (sfree & S2)
free(s2);
j = 0;
while (s2[j])
f[i++] = s2[j++];
f[i] = '\0';
return (f);
}
//LOL DOESNT WORK AND SEGFAULTS GHAHAH