This repository was archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathft_strjoin.c
More file actions
63 lines (56 loc) · 1.58 KB
/
ft_strjoin.c
File metadata and controls
63 lines (56 loc) · 1.58 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dground <dground@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 19:53:11 by dground #+# #+# */
/* Updated: 2021/10/08 20:40:34 by dground ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_strcat(char *dest, const char *src)
{
int i;
int j;
i = 0;
j = 0;
while (dest[i] != '\0')
{
i++;
}
while (src[j] != '\0')
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = '\0';
return (dest);
}
static char *ft_strcpy(char *dest, const char *scr)
{
int i;
i = 0;
while (scr[i] != '\0')
{
dest[i] = scr[i];
i++;
}
dest[i] = '\0';
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
int length;
if (s1 == NULL || s2 == NULL)
return (NULL);
length = ft_strlen(s1) + ft_strlen(s2) + 1;
str = (char *)malloc(sizeof(char) * length);
if (str == NULL)
return (NULL);
ft_strcpy(str, s1);
ft_strcat(str, s2);
return (str);
}