-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_ptrhex.c
More file actions
42 lines (39 loc) · 1.31 KB
/
ft_ptrhex.c
File metadata and controls
42 lines (39 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ptrhex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bschwitz <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/29 16:13:12 by bschwitz #+# #+# */
/* Updated: 2021/12/06 15:57:12 by bschwitz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <unistd.h>
int ft_ptrhex(void *ptr)
{
int i;
int j;
char hexa[100];
unsigned long nbr;
char *base;
base = "0123456789abcdef";
nbr = (unsigned long) ptr;
j = 0;
i = 0;
i = i + write(1, "0x", 2);
if (nbr == 0)
i = i + write(1, base, 1);
while (nbr != 0)
{
hexa[j++] = base[nbr % 16];
nbr = nbr / 16;
}
while (j != 0)
{
i = i + write(1, &hexa[j - 1], 1);
j--;
}
return (i);
}