-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
55 lines (50 loc) · 1.44 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkeuleya <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/08 16:03:28 by jkeuleya #+# #+# */
/* Updated: 2014/11/13 15:24:22 by jkeuleya ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static int ft_cmp(char const *s1, char const *s2)
{
int j;
j = 0;
if (s1)
j = ft_strlen(s1);
if (s2)
j = j + ft_strlen(s2);
return (j);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int j;
char *str;
i = 0;
if (s1 || s2)
{
j = ft_cmp(s1, s2);
if ((str = (char *)malloc(sizeof(char) * (j + 1))) == NULL)
return (NULL);
str[j] = '\0';
j = 0;
while (s1 && s1[i])
{
str[i] = s1[i];
i++;
}
while (s2 && s2[j])
{
str[i + j] = s2[j];
j++;
}
return (str);
}
return (NULL);
}