-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
executable file
·42 lines (39 loc) · 1.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mberger <mberger@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/12/23 19:51:36 by mberger #+# #+# */
/* Updated: 2014/12/23 19:52:07 by mberger ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int len;
int n;
int counter;
char *final;
if (s1 == NULL && s2 == NULL)
return ((char *)NULL);
if (s1 == NULL && s2)
return (ft_strdup(s2));
if (s2 == NULL && s1)
return (ft_strdup(s1));
counter = 0;
len = ft_strlen(s1);
n = len + ft_strlen(s2) + 1;
if (!(final = ft_strnew(n)))
return (NULL);
while (counter < n)
{
if (counter < len)
final[counter] = s1[counter];
else
final[counter] = s2[counter - len];
counter++;
}
return (final);
}