-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
48 lines (43 loc) · 1.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 12:06:55 by ana-lda- #+# #+# */
/* Updated: 2024/04/30 14:49:07 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/** @brief concatena duas strings.
@param s1 e s2 sao string a serem concatenadas.
@return uma nova string resultado da juncao de s1 e s2.
*/
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *str;
str = (char *)malloc(sizeof(*s1) * (ft_strlen(s1) + (ft_strlen(s2) + 1)));
if (!str)
return (NULL);
i = 0;
j = 0;
while (s1[i])
str[j++] = s1[i++];
i = 0;
while (s2[i])
str[j++] = s2[i++];
str[j] = 0;
return (str);
}
/*#include <stdio.h>
int main(void)
{
char const str1[] = "abc";
char const str2[] = "def";
printf("antes s2:%s\n", str1);
printf("antes s1:%s\n", str2);
printf("depois do join: %s\n", ft_strjoin(str1, str2));
}*/