-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_hexadem.c
More file actions
48 lines (41 loc) · 1.46 KB
/
ft_hexadem.c
File metadata and controls
48 lines (41 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hexadem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgalan-n <fgalan-n@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 11:29:38 by fgalan-n #+# #+# */
/* Updated: 2022/11/02 11:35:33 by fgalan-n ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_transform(unsigned int long num, char *str)
{
int x;
x = 0;
if (num >= 16)
{
x += ft_transform(num / 16, str);
x += ft_transform(num % 16, str);
}
else
x += ft_putchar(str[num % 16]);
return (x);
}
int ft_hexadecimal(unsigned int num, char c)
{
int x;
x = 0;
if (c == 'x')
x += ft_transform(num, "0123456789abcdef");
else
x += ft_transform(num, "0123456789ABCDEF");
return (x);
}
int ft_pointer(unsigned int long ptr)
{
int x;
x = ft_transform(ptr, "0123456789abcdef");
return (x);
}