-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
executable file
·44 lines (40 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/06 14:49:04 by ngouy #+# #+# */
/* Updated: 2015/11/04 17:01:48 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Create a new str and fill it with s1 and then s2.
*/
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int j;
char *rett;
if (!s1 || !s2)
return (NULL);
if (s1[0] == s2[0] && s2[0] == '\0')
{
rett = (char *)malloc(1);
rett[0] = '\0';
return (rett);
}
i = 0;
j = i;
rett = ft_strnew(ft_strlen(s1) + ft_strlen(s2));
if (!rett)
return (NULL);
while (s1[i])
rett[j++] = s1[i++];
i = 0;
while (s2[i])
rett[j++] = s2[i++];
return (rett);
}