-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
39 lines (36 loc) · 1.26 KB
/
ft_strjoin.c
File metadata and controls
39 lines (36 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sabahass <sabahass@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/17 23:07:18 by sabahass #+# #+# */
/* Updated: 2025/08/17 23:53:15 by sabahass ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *result;
size_t i;
size_t j;
if (!s1 || !s2)
return (NULL);
result = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (!result)
return (NULL);
i = 0;
j = 0;
while (s1[i])
{
result[i] = s1[i];
i++;
}
while (s2[j])
{
result[i++] = s2[j++];
}
result[i] = '\0';
return (result);
}