-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strconcat.c
executable file
·36 lines (33 loc) · 1.27 KB
/
ft_strconcat.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strconcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/07 00:18:10 by luperez #+# #+# */
/* Updated: 2014/11/22 14:10:02 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strconcat(char *s1, const char *s2)
{
char *s3;
int len;
char *save;
if (!s1 && !s2)
return (ft_strnew(1));
if (!s1)
return (ft_strdup(s2));
if (!s2)
return (ft_strdup(s1));
len = ft_strlen(s1) + ft_strlen((char *)s2);
s3 = (char *)malloc(sizeof(char) * len + 1);
save = s3;
while (*s1)
*s3++ = *s1++;
while (*s2)
*s3++ = *s2++;
*s3 = '\0';
return (save);
}