-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
46 lines (42 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcosta-d <gcosta-d@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/25 15:03:06 by gcosta-d #+# #+# */
/* Updated: 2021/09/14 10:17:45 by gcosta-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* Strjoin concatenate two string in one and return a pointer
* to the new string.
*/
char *ft_strjoin(char const *s1, char const *s2)
{
unsigned int i;
unsigned int j;
unsigned int s1_len;
unsigned int s2_len;
char *s3;
s1_len = ft_strlen(s1);
s2_len = ft_strlen(s2);
s3 = malloc(s1_len + s2_len + 1);
if (!s3)
return (NULL);
i = 0;
while (s1[i] != 0)
{
s3[i] = s1[i];
i++;
}
j = 0;
while (s2[j] != 0)
{
s3[i + j] = s2[j];
j++;
}
s3[i + j] = 0;
return (s3);
}