-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_ptr.c
56 lines (50 loc) · 1.39 KB
/
ft_print_ptr.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_print_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ygunay <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/18 14:43:28 by ygunay #+# #+# */
/* Updated: 2022/08/18 15:37:56 by ygunay ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_len_ptr(unsigned long nb)
{
int len;
len = 0;
while (nb != 0)
{
nb /= 16;
len++;
}
return (len);
}
static void ft_putptr(unsigned long nb)
{
if (nb >= 16)
{
ft_putptr(nb / 16);
ft_putptr(nb % 16);
}
else
{
if (nb <= 9)
ft_putchar(nb + '0');
else
ft_putchar(nb - 10 + 'a');
}
}
int ft_print_ptr(unsigned long nb)
{
int len;
len = 2;
write(1, "0x", 2);
if (nb == 0)
len += write(1, "0", 1);
else
ft_putptr(nb);
len += ft_len_ptr(nb);
return (len);
}