-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putptr.c
More file actions
58 lines (52 loc) · 1.42 KB
/
Copy pathft_putptr.c
File metadata and controls
58 lines (52 loc) · 1.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: astoll <astoll@student.42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/14 15:30:27 by astoll #+# #+# */
/* Updated: 2023/11/15 11:24:48 by astoll ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_ptrlen(uintptr_t ptr)
{
int count;
count = 0;
while (ptr != 0)
{
ptr /= 16;
count++;
}
return (count);
}
static void ft_ptrput(uintptr_t ptr)
{
if (ptr >= 16)
{
ft_ptrput(ptr / 16);
ft_ptrput(ptr % 16);
}
else
{
if (ptr <= 9)
ft_putchar(ptr + '0');
else
ft_putchar(ptr - 10 + 'a');
}
}
int ft_putptr(uintptr_t ptr)
{
int count;
count = 0;
count += write(1, "0x", 2);
if (ptr == 0)
count += write(1, "0", 1);
else
{
ft_ptrput(ptr);
count += ft_ptrlen(ptr);
}
return (count);
}