-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
55 lines (49 loc) · 1.6 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
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-haib <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 13:14:40 by ael-haib #+# #+# */
/* Updated: 2024/02/01 01:29:53 by ael-haib ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
size_t len_s1;
size_t len_s2;
char *total;
size_t i;
if (!s1 || !s2)
return (NULL);
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
total = (char *)malloc((len_s1 + len_s2 + 1) * sizeof(char));
if (!total)
return (NULL);
i = 0;
while (i < len_s1)
{
total[i++] = *s1++;
}
while (i < (len_s1 + len_s2))
{
total[i++] = *s2++;
}
total[i] = '\0';
return (total);
}
/* int main() {
const char* s1 = "whsup ";
const char* s2 = "bruh!";
char* result = ft_strjoin(s1, s2);
if (result != NULL) {
printf("The full string is: %s\n", result);
free(result);
} else {
printf("memory allocation failed or wrong input: Error\n");
}
return (0);
} */