-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_number.c
More file actions
54 lines (47 loc) · 1.65 KB
/
ft_printf_number.c
File metadata and controls
54 lines (47 loc) · 1.65 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_number.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mjusta <mjusta@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/02 11:15:23 by mjusta #+# #+# */
/* Updated: 2025/06/02 14:49:20 by mjusta ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_putnbr_base(unsigned long n, const char *base, unsigned int blen)
{
int count;
count = 0;
if (n >= blen)
count += ft_putnbr_base(n / blen, base, blen);
count += ft_putchar(base[n % blen]);
return (count);
}
int ft_putunsigned(unsigned int n)
{
return (ft_putnbr_base(n, "0123456789", 10));
}
int ft_puthex(unsigned int n, int upper)
{
if (upper)
return (ft_putnbr_base(n, "0123456789ABCDEF", 16));
else
return (ft_putnbr_base(n, "0123456789abcdef", 16));
}
int ft_putpointer(void *ptr)
{
unsigned long address;
int count;
count = 0;
address = (unsigned long)ptr;
if (!address)
count += ft_putstr("(nil)");
else
{
count += ft_putstr("0x");
count += ft_putnbr_base(address, "0123456789abcdef", 16);
}
return (count);
}