-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
64 lines (55 loc) · 1.7 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
56
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edetoh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/18 16:15:49 by edetoh #+# #+# */
/* Updated: 2024/10/25 11:17:41 by edetoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
* ft_strjoin concatenates two strings.
* Takes 's1' (first string) and 's2' (second string).
* Returns a new string resulting from the concatenation.
*/
char *ft_strjoin(char const *s1, char const *s2)
{
char *new_str;
size_t i;
size_t n;
i = 0;
n = 0;
new_str = malloc((ft_strlen((char *)s1) + \
ft_strlen((char *)s2) + 1) * sizeof(char));
if (!new_str)
return (NULL);
while (s1[n] != '\0')
{
new_str[i] = s1[n];
i++;
n++;
}
n = 0;
while (s2[n] != '\0')
{
new_str[i] = s2[n];
i++;
n++;
}
new_str[i] = 0;
return (new_str);
}
// #include <string.h>
// #include <stdio.h>
// #include <unistd.h>
// int main(void)
// {
// char *str1 = "&";
// char *str2 = "é";
// char *res = ft_strjoin(str1, str2);
// printf("===== RESULT =====\n%s\n==================", res);
// return (1);
// }