-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_pointers.c
61 lines (54 loc) · 1.62 KB
/
ft_pointers.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
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pointers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmacias- <gmacias-@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 18:24:10 by gmacias- #+# #+# */
/* Updated: 2022/02/23 19:04:45 by gmacias- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_length_pointer(unsigned long long ptr);
static void ft_search_pointer(unsigned long long ptr);
int ft_print_pointer(unsigned long long ptr)
{
int size;
size = 0;
size += ft_print_string("0x");
if (ptr == 0)
size += ft_print_character('0');
else
{
ft_search_pointer(ptr);
size += ft_length_pointer(ptr);
}
return (size);
}
static int ft_length_pointer(unsigned long long ptr)
{
int len;
len = 0;
while (ptr > 0)
{
len++;
ptr /= 16;
}
return (len);
}
static void ft_search_pointer(unsigned long long ptr)
{
if (ptr >= 16)
{
ft_search_pointer(ptr / 16);
ft_search_pointer(ptr % 16);
}
else
{
if (ptr < 10)
ft_print_character(ptr + '0');
else
ft_print_character(ptr - 10 + 'a');
}
}