-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putp.c
55 lines (50 loc) · 1.4 KB
/
ft_putp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vstockma <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/19 14:22:01 by vstockma #+# #+# */
/* Updated: 2022/10/19 14:22:02 by vstockma ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void ft_putptr(long unsigned int i)
{
char *arr;
arr = "0123456789abcdef";
if (i >= 16)
{
ft_putptr(i / 16);
ft_putptr(i % 16);
}
else
ft_putchar(arr[i]);
}
int ft_putp(va_list args)
{
int len;
long unsigned int ptr;
ptr = va_arg(args, long unsigned int);
len = 0;
if (ptr == 0)
{
write(1, "(nil)", 5);
return (5);
}
if (ptr != 0)
{
write(1, "0x", 2);
len = 2;
}
ft_putptr(ptr);
if (ptr == 0)
len++;
while (ptr > 0)
{
ptr = ptr / 16;
len++;
}
return (len);
}