-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_p.c
More file actions
64 lines (55 loc) · 1.56 KB
/
ft_print_p.c
File metadata and controls
64 lines (55 loc) · 1.56 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
55
56
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_p.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bhielsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/20 10:37:55 by bhielsch #+# #+# */
/* Updated: 2022/10/20 13:55:59 by bhielsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void ft_putchar(char c);
static int ft_print_hexlowp(unsigned long nb, int count);
int ft_print_p(void *ptr)
{
unsigned long size;
unsigned long i;
i = (unsigned long) ptr;
if (i == 0)
return (write (1, "(nil)", 5));
write (1, "0x", 2);
size = ft_print_hexlowp(i, 1);
return (size + 2);
}
int ft_print_hexlowp(unsigned long nb, int count)
{
int i;
i = count;
if (nb >= 16)
{
i++;
i = ft_print_hexlowp(nb / 16, i);
nb = nb % 16;
}
if (nb < 10)
{
ft_putchar(nb + 48);
}
else
{
ft_putchar(nb + 87);
}
return (i);
}
void ft_putchar(char c)
{
write(1, &c, 1);
}
// int main()
// {
// int nb = -1;
// void *ptr = &nb;
// ft_print_p(ptr);
// }