-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_base.c
45 lines (40 loc) · 1.45 KB
/
ft_putnbr_base.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkoupy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/20 16:04:42 by jkoupy #+# #+# */
/* Updated: 2023/09/21 16:31:10 by jkoupy ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_puthexa(int nbr, char spec)
{
int printlen;
printlen = 0;
if (spec == 'x')
printlen += ft_putnbr_base(nbr, "0123456789abcdef");
else if (spec == 'X')
printlen += ft_putnbr_base(nbr, "0123456789ABCDEF");
return (printlen);
}
int ft_putnbr_base(unsigned int nbr, char *base)
{
unsigned int base_num;
int printlen;
printlen = 0;
base_num = ft_strlen(base);
if (nbr >= base_num)
{
printlen += ft_putnbr_base(nbr / base_num, base);
nbr %= base_num;
}
if (nbr < base_num)
{
ft_putchar_fd(base[nbr], 1);
printlen++;
}
return (printlen);
}