-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
63 lines (58 loc) · 1.77 KB
/
ft_printf.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
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iidzim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 11:03:34 by iidzim #+# #+# */
/* Updated: 2019/11/20 15:14:52 by iidzim ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_init(t_flags *flg)
{
flg->align = 0;
flg->width = 0;
flg->zero = 0;
flg->prec = -1;
}
void ft_check(int *i, va_list args, char *str, t_flags flg)
{
if (str[*i] == 'd' || str[*i] == 'i')
ft_convert_d(args, flg);
if (str[*i] == 'u')
ft_convert_u(args, flg);
if (str[*i] == 'x' || str[*i] == 'X')
ft_convert_hexa(args, flg, str[*i]);
if (str[*i] == 'p')
ft_convert_p(args, flg);
if (str[*i] == 's')
ft_convert_s(args, flg);
if (str[*i] == 'c')
ft_convert_c(args, flg);
if (str[*i] == '%')
ft_convert_per(flg);
}
int ft_printf(const char *str, ...)
{
va_list args;
t_flags flg;
int i;
i = -1;
g_r = 0;
va_start(args, str);
while (str[++i] != '\0')
{
if (str[i] == '%')
{
ft_init(&flg);
ft_more_flags(args, (char *)str, &i, &flg);
ft_check(&i, args, (char *)str, flg);
}
else
ft_putchar(str[i]);
}
va_end(args);
return (g_r);
}