-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_p_convert.c
54 lines (50 loc) · 1.54 KB
/
ft_p_convert.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
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_p_convert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahaifoul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/21 18:28:38 by ahaifoul #+# #+# */
/* Updated: 2021/11/23 12:11:01 by ahaifoul ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int base_convert_p(void *x)
{
int j;
int tab[100];
unsigned long int nb;
int i;
char *base;
base = "0123456789abcdef";
nb = (unsigned long int)x;
j = 0;
i = ft_putstr("0x");
if (nb == 0)
i += ft_putchar(base[0]);
while (nb)
{
tab[j++] = nb % 16;
nb = nb / 16;
}
while (--j >= 0)
i += ft_putchar(base[tab[j]]);
return (i);
}
int base_convert_hex(long int nb, char c)
{
char *base;
char *base1;
int i;
i = 0;
base = "0123456789abcdef";
base1 = "0123456789ABCDEF";
if (nb == 0)
i += ft_putchar(base[0]);
else if (c == 'x')
i += base_convert_x(nb);
else if (c == 'X')
i += base_convert_up(nb);
return (i);
}