-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_ptr_printf.c
58 lines (51 loc) · 1.7 KB
/
ft_ptr_printf.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
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ptr_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ***REMOVED*** <***REMOVED***@student.***REMOVED***.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/13 16:05:47 by ***REMOVED*** #+# #+# */
/* Updated: 2023/10/18 18:37:52 by ***REMOVED*** ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void print_hex(unsigned long number, t_pf_data *data)
{
if (number < 10)
ft_putchar_fd('0' + number, 1, data);
else
ft_putchar_fd('a' + number - 10, 1, data);
}
static void get_bytes(t_pf_data *data, unsigned long pointer)
{
if (!pointer || data->error)
return ;
get_bytes(data, pointer / 16);
print_hex(pointer % 16, data);
data->letter_count++;
}
void ft_print_ptr(t_pf_data *data)
{
unsigned long pointer;
ft_putstr_fd("0x", 1, data);
if (data->error)
return ;
data->letter_count += 2;
data->string_position++;
pointer = (unsigned long)va_arg(*(data->arguments), void *);
if (!pointer)
{
ft_putchar_fd('0', 1, data);
data->letter_count++;
}
else
get_bytes(data, pointer);
}
/* int main()
{
int x;
x = 42;
print_ptr(&x);
return (0);
} */