-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
52 lines (48 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalcabre <dalcabre@student.42urduliz.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 14:02:34 by dalcabre #+# #+# */
/* Updated: 2024/01/25 16:51:59 by dalcabre ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *s3;
if (!s1 || !s2)
return (NULL);
i = 0;
j = 0;
s3 = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!s3)
return (NULL);
while (s1[i])
{
s3[i] = s1[i];
i++;
}
while (s2[j])
{
s3[i] = s2[j];
i++;
j++;
}
s3[i] = '\0';
return (s3);
}
/*#include <stdio.h>
int main(void)
{
const char *s1 = "Hi,";
const char *s2 = " im Edu";
const char *result = ft_strjoin(s1, s2);
printf("La nueva string es: %s", result);
free((void *)result);
return (0);
}*/