-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
39 lines (36 loc) · 1.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cyfermie <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 16:02:24 by cyfermie #+# #+# */
/* Updated: 2017/11/09 16:25:35 by cyfermie ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2)
{
size_t index_1;
size_t index_2;
char *strjoin;
if (s1 == NULL || s2 == NULL)
return (NULL);
index_1 = 0;
index_2 = 0;
while (s1[index_1] != '\0')
++index_1;
while (s2[index_2] != '\0')
++index_2;
strjoin = (char *)malloc(sizeof(char) * (index_1 + index_2 + 1));
if (strjoin == NULL)
return (NULL);
index_1 = 0;
while (*s1 != '\0')
strjoin[index_1++] = *s1++;
while (*s2 != '\0')
strjoin[index_1++] = *s2++;
strjoin[index_1] = '\0';
return (strjoin);
}