-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strjoin.c
35 lines (32 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-mlil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/26 16:58:22 by sel-mlil #+# #+# */
/* Updated: 2024/10/28 04:27:03 by sel-mlil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int j;
char *ptr;
if (!s1 && !s2)
return (ft_strdup(""));
ptr = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!ptr)
return (NULL);
j = 0;
i = 0;
while (s1[i])
ptr[j++] = s1[i++];
i = 0;
while (s2[i])
ptr[j++] = s2[i++];
ptr[j] = '\0';
return (ptr);
}