-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
77 lines (69 loc) · 1.87 KB
/
ft_printf_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zyacoubi <mrx.ga10@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 23:44:08 by zyacoubi #+# #+# */
/* Updated: 2021/12/05 23:44:13 by zyacoubi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_check(const char *str, va_list list, int *j, int i)
{
string_tr(&str[i], list, j);
hex_tr(&str[i], list, j);
udi_tr(&str[i], list, j);
}
void ft_hex(unsigned int x, int i, int *r)
{
if (x >= 16)
{
ft_hex(x / 16, i, r);
ft_hex(x % 16, i, r);
}
else
{
if (i == 0)
*r += write(1, &"0123456789ABCDEF"[x], 1);
else if (i == 1)
*r += write(1, &"0123456789abcdef"[x], 1);
}
}
void ft_putnbr(int nb, int *r)
{
char *num;
num = "0123456789";
if (nb == -2147483648)
{
*r += write(1, "-2147483648", 11);
return ;
}
if (nb < 0)
{
*r += write(1, "-", 1);
nb *= -1;
}
if (nb >= 10)
ft_putnbr(nb / 10, r);
*r += write(1, &num[nb % 10], 1);
}
void ft_hexp(unsigned long x, int *r)
{
char *hex;
hex = "0123456789abcdef";
if (x >= 16)
ft_hexp(x / 16, r);
*r += write(1, &hex[x % 16], 1);
}
void unsigned_tr(unsigned int n, int *r)
{
if (n >= 10)
{
unsigned_tr(n / 10, r);
unsigned_tr(n % 10, r);
}
else
*r += write(1, &"0123456789"[n], 1);
}