-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_help.c
101 lines (93 loc) · 1.89 KB
/
ft_help.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
89
90
91
92
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_help.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/29 19:04:33 by zwalad #+# #+# */
/* Updated: 2021/11/30 17:06:15 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_norm1(int nbr, int size)
{
if (nbr < 0)
{
nbr *= -1;
size++;
}
if (nbr == 0)
return (1);
while (nbr)
{
nbr /= 10;
size++;
}
return (size);
}
int ft_putnbr(int nbr)
{
int size;
int nb;
if (nbr == -2147483648)
{
ft_putstr("-2147483648");
return (11);
}
nb = nbr;
if (nbr < 0)
{
nbr *= -1;
ft_putchar('-');
}
if (nbr <= 9)
ft_putchar(nbr + '0');
if (nbr > 9)
{
ft_putnbr(nbr / 10);
ft_putnbr(nbr % 10);
}
size = ft_norm1(nb, 0);
return (size);
}
int ft_hexa(unsigned int nb, char *s)
{
int size;
if (nb < 16)
ft_putchar(s[nb]);
else if (nb >= 16)
{
ft_hexa(nb / 16, s);
ft_hexa(nb % 16, s);
}
size = 0;
if (nb == 0)
return (1);
while (nb)
{
nb /= 16;
size++;
}
return (size);
}
int ft_pupo(unsigned long long nb, char *s)
{
int size;
if (nb < 16)
ft_putchar(s[nb]);
if (nb >= 16)
{
ft_pupo(nb / 16, s);
ft_pupo(nb % 16, s);
}
size = 0;
if (nb == 0)
return (1);
while (nb)
{
nb /= 16;
size++;
}
return (size);
}