-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_memory.c
53 lines (49 loc) · 1.57 KB
/
print_memory.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_memory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmanyani <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/30 13:34:47 by mmanyani #+# #+# */
/* Updated: 2024/12/13 12:51:24 by mmanyani ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int recursive_call_mem(unsigned long mem, int *count)
{
if (mem >= 16)
{
if (recursive_call_mem(mem / 16, count) == -1)
return (-1);
}
if (mem % 16 < 10)
{
if (error_check(count, print_char(mem % 16 + '0')) == -1)
return (-1);
}
else
{
if (error_check(count, print_char(mem % 16 - 10 + 'a')) == -1)
return (-1);
}
return (0);
}
int print_memory(unsigned long mem)
{
int printed;
printed = 0;
if (mem == 0)
{
if (error_check(&printed, print_string("(nil)")) == -1)
return (-1);
}
else
{
if (error_check(&printed, print_string("0x")) == -1)
return (-1);
if (recursive_call_mem(mem, &printed) == -1)
return (-1);
}
return (printed);
}