-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
executable file
·40 lines (37 loc) · 1.24 KB
/
ft_strjoin.c
File metadata and controls
executable file
·40 lines (37 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abelkhad <abelkhad@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/15 10:54:51 by tnaceur #+# #+# */
/* Updated: 2023/03/06 21:25:44 by abelkhad ### ########.fr */
/* */
/* ************************************************************************** */
#include"cub.h"
char *ft_strjoin(char *s1, char *s2)
{
size_t i;
size_t j;
char *ptr;
if (!s1)
return (s2);
if (!s2)
return (s1);
i = ft_strlen(s1);
j = ft_strlen(s2);
ptr = malloc(i + j + 1);
i = -1;
while (s1[++i])
ptr[i] = s1[i];
j = 0;
while (s2[j])
ptr[i++] = s2[j++];
ptr[i] = '\0';
free(s1);
free(s2);
s1 = NULL;
s2 = NULL;
return (ptr);
}