-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_printf_cs_pct.c
59 lines (54 loc) · 1.78 KB
/
ft_printf_cs_pct.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
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_csp_pct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:36:54 by apuchill #+# #+# */
/* Updated: 2020/05/30 22:08:03 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void print_padding(int *len, t_flags fl)
{
while (fl.width > fl.precision)
{
ft_putchar_len(fl.pad_c, len);
fl.width--;
}
}
void print_spec_pct(int *len, t_flags fl)
{
if (fl.minus == 1)
fl.pad_c = ' ';
fl.precision = 1;
if (fl.minus == 0)
print_padding(len, fl);
ft_putchar_len('%', len);
if (fl.minus == 1)
print_padding(len, fl);
}
void print_spec_c(int *len, t_flags fl, char c)
{
fl.pad_c = ' ';
fl.precision = 1;
if (fl.minus == 0)
print_padding(len, fl);
ft_putchar_len(c, len);
if (fl.minus == 1)
print_padding(len, fl);
}
void print_spec_s(int *len, t_flags fl, char *s)
{
fl.pad_c = ' ';
if (s == NULL)
s = "(null)";
if ((fl.point == 1 && fl.precision > (int)ft_strlen(s)) || fl.point == 0)
fl.precision = ft_strlen(s);
if (fl.minus == 0)
print_padding(len, fl);
ft_putcstr_len(s, len, fl.precision);
if (fl.minus == 1)
print_padding(len, fl);
}