-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
42 lines (39 loc) · 1.34 KB
/
ft_strjoin.c
File metadata and controls
42 lines (39 loc) · 1.34 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jelefebv <jelefebv@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/10 10:10:26 by jelefebv #+# #+# */
/* Updated: 2014/11/27 20:34:13 by jelefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2)
{
unsigned int lens2;
char *a;
unsigned int i;
i = 0;
if (s1 == NULL || s2 == NULL)
return (NULL);
lens2 = ft_strlen(s2);
a = (char *)malloc(ft_strlen(s1) + lens2 + 1);
if (a == NULL)
return (NULL);
while (i < ft_strlen(s1))
{
a[i] = s1[i];
i++;
}
i = 0;
while (i < lens2)
{
a[ft_strlen(s1) + i] = s2[i];
i++;
}
a[lens2 + ft_strlen(s1)] = '\0';
return (a);
}