-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
38 lines (35 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pboonpro <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/04 00:01:26 by pboonpro #+# #+# */
/* Updated: 2022/08/04 02:01:58 by pboonpro ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int lens1;
int lens2;
char *ptr;
int i;
lens1 = ft_strlen(s1);
lens2 = ft_strlen(s2);
ptr = malloc(sizeof(char) * (lens1 + lens2) + 1);
if (ptr == 0)
return (0);
i = 0;
while (i < lens1 + lens2)
{
if (i < lens1)
ptr[i] = s1[i];
else if (i >= lens1 && i < lens1 + lens2)
ptr[i] = s2[i - lens1];
i++;
}
ptr[i] = '\0';
return (ptr);
}