-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_util.c
51 lines (46 loc) · 1.63 KB
/
ft_printf_util.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnakano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/12 15:28:17 by dnakano #+# #+# */
/* Updated: 2020/10/18 13:08:45 by dnakano ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_printf_getwidth(int width_arg, t_printf_flags *flags)
{
if (width_arg < 0)
{
flags->width = -width_arg;
flags->flag = flags->flag | FLAG_LEFTADJUST;
}
else
flags->width = width_arg;
}
void ft_printf_initflags(t_printf_flags *flags)
{
flags->width = -1;
flags->precision = -1;
flags->flag = 0;
}
void ft_printf_putsign(int flag_neg, t_printf_flags *flags)
{
if (flag_neg)
ft_putchar_fd('-', 1);
else if (flags->flag & FLAG_PUTPOSSIGN)
ft_putchar_fd('+', 1);
else if (flags->flag & FLAG_PUTPOSSPACE)
ft_putchar_fd(' ', 1);
}
void ft_printf_putintalternate(const char fc)
{
if (fc == 'x' || fc == 'p')
ft_putstr_fd("0x", 1);
else if (fc == 'X')
ft_putstr_fd("0X", 1);
else if (fc == 'o')
ft_putchar_fd('0', 1);
}