-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_put_X.c
88 lines (77 loc) · 1.9 KB
/
ft_put_X.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
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_X.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariahi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/10 13:47:39 by ariahi #+# #+# */
/* Updated: 2022/01/10 13:47:42 by ariahi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
///////////////////////////////////////////xlen
int ft_xlen(unsigned long long hex)
{
int len;
len = 0;
while (hex != 0)
{
hex = hex / 16;
len++;
}
return (len);
}
///////////////////////////////////////////hexa
int ft_putx(unsigned int nb, const char str)
{
if (nb >= 16)
{
ft_putx(nb / 16, str);
ft_putx(nb % 16, str);
}
else
{
if (nb <= 9)
return (ft_putchar(nb + '0'));
else
{
if (str == 'x')
ft_putchar((nb - 10 + 'a'));
else
ft_putchar((nb - 10 + 'A'));
}
}
return (ft_xlen(nb));
}
///////////////////////////////////////////ptr
int ft_puthexa(unsigned long long hex)
{
if (hex >= 16)
{
ft_puthexa(hex / 16);
ft_puthexa(hex % 16);
}
else
{
if (hex <= 9)
return (ft_putchar(hex + '0'));
else
ft_putchar((hex - 10 + 'a'));
}
return (ft_xlen(hex));
}
////////////////////////////////////////////str
int ft_putstr(char *str)
{
int i;
i = 0;
if (!str)
return (write(1, "(null)", 6));
while (str[i])
{
write(1, &str[i], 1);
i++;
}
return (i);
}