maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_print_ptr.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_print_ptr.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: rocky <rmikhayl@student.42london.com> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2024/01/07 15:47:43 by rocky #+# #+# */
9
/* Updated: 2024/01/07 15:47:43 by rocky ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
libft.h
"
14
15
int
ft_ptr_len
(uintptr_t num)
16
{
17
int
len;
18
19
len = 0;
20
while
(num != 0)
21
{
22
len++;
23
num = num / 16;
24
}
25
return
(len);
26
}
27
28
void
ft_put_ptr
(uintptr_t num)
29
{
30
if
(num >= 16)
31
{
32
ft_put_ptr
(num / 16);
33
ft_put_ptr
(num % 16);
34
}
35
else
36
{
37
if
(num <= 9)
38
ft_putchar_fd
((num +
'0'
), 1);
39
else
40
ft_putchar_fd
((num - 10 +
'a'
), 1);
41
}
42
}
43
44
int
ft_print_ptr
(
unsigned
long
long
ptr)
45
{
46
int
print_length;
47
48
print_length = 0;
49
if
(ptr == 0)
50
print_length += write(1,
"(nil)"
, 5);
51
else
52
{
53
print_length += write(1,
"0x"
, 2);
54
ft_put_ptr
(ptr);
55
print_length +=
ft_ptr_len
(ptr);
56
}
57
return
(print_length);
58
}
ft_print_ptr
int ft_print_ptr(unsigned long long ptr)
Definition
ft_print_ptr.c:44
ft_put_ptr
void ft_put_ptr(uintptr_t num)
Definition
ft_print_ptr.c:28
ft_ptr_len
int ft_ptr_len(uintptr_t num)
Definition
ft_print_ptr.c:15
libft.h
ft_putchar_fd
void ft_putchar_fd(char c, int fd)
Definition
ft_putchar_fd.c:20
lib
libft
src
ft_print_ptr.c
Generated by
1.9.8