-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_ptr.c
67 lines (59 loc) · 1.65 KB
/
ft_printf_ptr.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
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vess <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/07 18:09:37 by jcampagn #+# #+# */
/* Updated: 2021/12/11 12:33:15 by jcampagn ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_strcmp(const char *s1, const char *s2)
{
int i;
i = 0;
while (s1[i] != '\0' && s2[i] != '\0' && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}
int ft_ptrlen(unsigned long long nb)
{
int i;
i = 0;
while (nb > 0)
{
i++;
nb = nb / 16;
}
return (i);
}
void ft_putptr(unsigned long long nb)
{
char *basex;
basex = "0123456789abcdef";
if (nb >= 16)
{
ft_putptr(nb / 16);
ft_putptr(nb % 16);
}
else
{
ft_putchar(basex[nb]);
}
}
int ft_printptr(unsigned long long int nb)
{
if (nb == 0)
{
ft_putstr(RETURN_NULL);
if (!ft_strcmp(RETURN_NULL, (char *)"(nil)"))
return (5);
if (!ft_strcmp(RETURN_NULL, (char *)"0x0"))
return (3);
}
ft_putstr("0x");
ft_putptr(nb);
return (ft_ptrlen(nb) + 2);
}