-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printnu_base.c
56 lines (50 loc) · 1.49 KB
/
ft_printnu_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
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printnu_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ghuertas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/13 19:25:17 by ghuertas #+# #+# */
/* Updated: 2022/05/15 20:25:39 by ghuertas ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static size_t ft_num_len(unsigned int n)
{
size_t len;
len = 0;
if (n == 0)
len = 1;
while (n != 0)
{
(n /= 10);
len++;
}
return (len);
}
int ft_printnu_base(unsigned int n, char *base)
{
unsigned int bhex;
bhex = ft_strlenv2(base);
if (n == 2147483648)
{
ft_print_char('2');
ft_printn_base(147483648, base);
}
else if (n < bhex)
ft_print_char(base[n]);
else
{
ft_printnu_base(n / bhex, base);
ft_print_char(base[n % bhex]);
}
return (ft_num_len(n));
}
/*
int main(void)
{
const char typhex[] = "0123456789";
printf("%u\n", printn_base(2147483647, &typex));
return (0)
}*/