-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmidjoin.c
48 lines (43 loc) · 1.42 KB
/
ft_strmidjoin.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
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/18 13:48:34 by jraymond #+# #+# */
/* Updated: 2018/06/18 16:12:52 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
char *cpy(char *dest, char const *src)
{
int x;
x = 0;
if (!src)
return (dest);
while (src[x])
{
dest[x] = src[x];
x++;
}
return (&dest[x]);
}
char *ft_strmidjoin(char const *s1, char const *s2, char *middle)
{
char *new;
char *tmp;
int len;
if (!s1)
return (NULL);
len = ft_strlen(middle) + ft_strlen(s1) + ft_strlen(s2);
if (!(new = (char*)malloc(sizeof(char) * len + 1)))
return (NULL);
tmp = new;
new = cpy(new, s1);
new = cpy(new, middle);
new = cpy(new, s2);
*new = '\0';
return (tmp);
}