-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_pointer.c
More file actions
59 lines (51 loc) · 1.66 KB
/
ft_print_pointer.c
File metadata and controls
59 lines (51 loc) · 1.66 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vpogorel <vpogorel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/30 14:03:01 by vpogorel #+# #+# */
/* Updated: 2024/12/05 17:09:07 by vpogorel ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static char get_hex_digit(int digit)
{
char *digit_hex;
digit_hex = "0123456789abcdef";
return (digit_hex[digit]);
}
static void print_hex(unsigned long long n, int *count)
{
char digit;
if (n == 0)
return ;
print_hex(n / 16, count);
digit = get_hex_digit(n % 16);
write(1, &digit, 1);
(*count)++;
}
static void ft_print_pointer_hex(unsigned long long n, int *count)
{
print_hex(n, count);
if (n == 0)
{
write(1, "0", 1);
(*count)++;
}
}
void ft_print_pointer(va_list args, int *count)
{
unsigned long long number_pointer;
number_pointer = (unsigned long long)(va_arg(args, void *));
if (number_pointer == 0)
{
write(1, "(nil)", 5);
(*count) += 5;
return ;
}
write(1, "0x", 2);
(*count) += 2;
ft_print_pointer_hex(number_pointer, count);
}