-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strwfjoin.c
43 lines (39 loc) · 1.43 KB
/
ft_strwfjoin.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strwfjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/17 15:02:40 by ewilliam #+# #+# */
/* Updated: 2017/01/17 15:03:00 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
/*joins strings, and returns the len*/
#include "libft.h"
#include "printf.h"
#include <stdio.h>
int ft_strwfjoin(t_print *p, const char *new, int len)
{
char *tmp;
int old_len;
int total_len;
len = len < 0 ? (int)ft_strlen(new) : len;
old_len = p->out == NULL
? 0
: p->r;
total_len = p->out == NULL
? len
: len + old_len;
tmp = ft_strnew(total_len);
if (p->out == NULL)
ft_memmove(tmp, new, len);
else
{
ft_memmove(tmp, p->out, old_len);
ft_memmove(tmp + old_len, new, len);
ft_strdel(&(p->out));
}
p->out = tmp;
return (total_len);
}