-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_flags.c
84 lines (75 loc) · 2.26 KB
/
ft_flags.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_flags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmatheis <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/25 15:02:17 by jmatheis #+# #+# */
/* Updated: 2022/05/27 11:23:49 by jmatheis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
//c,s,i,d
//u: unsigned decimal (base 10), max_int+1 - negative input,
//in case of pos no. it stays the same
//x & X: hexadecimal (base 16) lowercase & uppercase format
//p: (pointer -> address) "0x" + no. in hexadecimal
void flags(va_list ptr, int *counter, char print)
{
unsigned int output;
if (print == 'u')
{
output = va_arg(ptr, unsigned int);
ft_u_putnbr(output, counter);
}
else if (print == 'x')
{
output = va_arg(ptr, unsigned int);
ft_p_x_putnbr(output, counter);
}
else if (print == 'X')
{
output = va_arg(ptr, unsigned int);
ft_bigx_putnbr(output, counter);
}
else if (print == '%')
{
ft_putchar('%');
(*counter)++;
}
}
void flags2(va_list ptr, int *counter, char print)
{
char *output3;
int output4;
if (print == 's')
{
output3 = va_arg(ptr, char *);
ft_putstr(output3, counter);
}
else if (print == 'd' || print == 'i')
{
output4 = va_arg(ptr, int);
ft_putnbr(output4, counter);
}
else if (print == 'c')
{
ft_putchar((char)va_arg(ptr, int));
(*counter)++;
}
}
void flags3(va_list ptr, int *counter, char print)
{
unsigned long int output2;
if (print == 'p')
{
write(1, "0x", 2);
*counter = *counter + 2;
output2 = va_arg(ptr, unsigned long int);
ft_p_x_putnbr(output2, counter);
}
}
// int counter in printf
// int *counter = &counter -> value of counter
// incrementing *counter --> incrementing val of counter