-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
41 lines (38 loc) · 1.3 KB
/
Copy pathft_strjoin.c
File metadata and controls
41 lines (38 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amennad <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 10:20:27 by amennad #+# #+# */
/* Updated: 2023/04/25 09:37:05 by amennad ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int y;
char *result;
i = 0;
y = 0;
if (!s1 || !s2)
return (NULL);
result = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!result)
return (NULL);
while (s1[i] != '\0')
{
result[i] = s1[i];
i++;
}
while (s2[y] != '\0')
{
result[i + y] = s2[y];
y++;
}
result[i + y] = '\0';
return (result);
}