-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_ptr.c
More file actions
60 lines (53 loc) · 1.47 KB
/
Copy pathft_print_ptr.c
File metadata and controls
60 lines (53 loc) · 1.47 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
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vcodrean <vcodrean@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/28 10:56:22 by vcodrean #+# #+# */
/* Updated: 2022/12/28 11:11:40 by vcodrean ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar_fd(char c, int fd);
int ft_ptr_len(uintptr_t num)
{
int len;
len = 0;
while (num != 0)
{
len++;
num = num / 16;
}
return (len);
}
void ft_put_ptr(uintptr_t num)
{
if (num >= 16)
{
ft_put_ptr(num / 16);
ft_put_ptr(num % 16);
}
else
{
if (num <= 9)
ft_putchar_fd((num + '0'), 1);
else
ft_putchar_fd((num - 10 + 'a'), 1);
}
}
int ft_print_ptr(uintptr_t ptr)
{
int lenght;
lenght = 0;
lenght += write(1, "0x", 2);
if (ptr == 0)
lenght += write(1, "0", 1);
else
{
ft_put_ptr(ptr);
lenght += ft_ptr_len(ptr);
}
return (lenght);
}