-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoinf.c
41 lines (38 loc) · 1.34 KB
/
ft_strjoinf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoinf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 13:09:10 by zhabri #+# #+# */
/* Updated: 2022/12/19 13:44:16 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strjoinf(char *s1, char const *s2)
{
int i;
int j;
int len;
char *str;
len = 0;
if (s1 && s2)
len = ft_strlen(s1) + ft_strlen(s2);
else if (s1)
len = ft_strlen(s1);
else if (s2)
len = ft_strlen(s2);
str = malloc((len + 1) * sizeof(char));
if (!str)
return (str);
i = -1;
while (s1 && i++ < len && s1[i])
str[i] = s1[i];
j = 0;
while (s2 && i < len && s2[j])
str[i++] = s2[j++];
str[i] = '\0';
free(s1);
return (str);
}