-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
66 lines (61 loc) · 2.08 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
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ribana-b <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/02 13:11:18 by ribana-b #+# #+# */
/* Updated: 2023/10/20 04:03:21 by ribana-b ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char *dst, const char *src)
{
char *str;
int index;
int index2;
index = ft_strlen(dst);
index2 = ft_strlen(src);
str = (char *)malloc((index + index2 + 1) * sizeof(char));
if (str == NULL)
return (NULL);
str[index + index2] = '\0';
while (index2-- > 0)
{
str[index + index2] = src[index2];
}
while (index-- > 0)
{
str[index] = dst[index];
}
return (str);
}
/* //This is for testing
#include <stdio.h>
int main(void)
{
char s1[] = "hola";
char s2[] = "adios";
printf("a%s", ft_strjoin(s1, s2));
}
*/
/*
RRRRR
RRR RRR
RRR RRR
RR RRRRRRRRRRRRRRRR
RRR RRRR RRRRRR
RRR RRR RRR
RRRRRRRR RRRR
RRR RRRRR
RRR RRR
RRR RRRR
RRR RRRRR
RRRRRRRRRRRRRR
RRRR RRRR
RRRR RRR
RRRR RRR
RRR RRR RRRRR
RRRR RRRRRRRR
*/