-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_5.c
More file actions
67 lines (62 loc) · 1.99 KB
/
print_5.c
File metadata and controls
67 lines (62 loc) · 1.99 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vportell <vportell@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/24 04:31:12 by vportell #+# #+# */
/* Updated: 2016/12/24 04:31:31 by vportell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void print_err(char *s, t_string **str, t_format **format)
{
char *p;
char *t;
char *n;
if ((*format)->min_width > 0)
{
p = ft_strnew((*format)->min_width - 1);
if ((*format)->flag->zero)
p = ft_memset(p, 48, (*format)->min_width - 1);
else
p = ft_memset(p, 32, (*format)->min_width - 1);
}
else
p = ft_strdup("");
n = ft_strnew(2);
n[0] = s[0];
t = (*format)->flag->minus ? ft_strjoin(n, p) : ft_strjoin(p, n);
append_str(t, str, *format);
ft_strdel(&p);
ft_strdel(&n);
ft_strdel(&t);
free((*format)->flag);
free(*format);
}
void print_pct(t_string **str, t_format **format)
{
char *t;
char *p;
char *s;
s = ft_strnew(2);
s[0] = '%';
if ((*format)->min_width > 0)
{
p = ft_strnew((*format)->min_width - 1);
if ((*format)->flag->zero)
p = ft_memset(p, 48, (*format)->min_width - 1);
else
p = ft_memset(p, 32, (*format)->min_width - 1);
t = ft_strdup(s);
ft_strdel(&s);
s = (*format)->flag->minus ? ft_strjoin(t, p) : ft_strjoin(p, t);
ft_strdel(&t);
ft_strdel(&p);
}
append_str(s, str, *format);
free((*format)->flag);
free(*format);
ft_strdel(&s);
}