-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_adresse.c
41 lines (36 loc) · 1.39 KB
/
ft_adresse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_adresse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zbabahmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/31 07:26:33 by zbabahmi #+# #+# */
/* Updated: 2022/10/31 07:26:34 by zbabahmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_adresse_hex(unsigned long int n, char c, int *len)
{
unsigned long int base_max;
char *base;
base_max = 16;
if (c == 'x')
base = "0123456789abcdef";
else
base = "0123456789ABCDEF";
if (n < base_max)
ft_putchar(base[n % base_max], len);
else
{
ft_adresse_hex(n / base_max, c, len);
ft_adresse_hex(n % base_max, c, len);
}
}
void ft_adresse(void *ad, int *len)
{
unsigned long int ptr;
ptr = (unsigned long int)ad;
ft_putstr("0x", len);
ft_adresse_hex(ptr, 'x', len);
}