-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_argument_p.c
36 lines (33 loc) · 1.37 KB
/
ft_argument_p.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_argument_p.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acesar-l <acesar-l@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/14 19:00:10 by acesar-l #+# #+# */
/* Updated: 2022/02/18 21:04:37 by acesar-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_argument_p(unsigned long address)
{
char *num;
int bytes;
int i;
i = 0;
if (!address)
return (write(1, "(nil)", sizeof(char) * 5));
bytes = write(1, "0x", sizeof(char) * 2);
num = (char *)malloc(((ft_hex_length(address)) + 1) * sizeof(char));
while (address)
{
num[i] = ft_decimal_converter_to_hex(address % 16, 'x');
address /= 16;
i++;
}
num[i] = '\0';
bytes += ft_print_reversed_str(num);
ft_free_ptr(&num);
return (bytes);
}