-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printer.c
76 lines (69 loc) · 1.62 KB
/
ft_printer.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
68
69
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rrangwan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/25 19:16:41 by rrangwan #+# #+# */
/* Updated: 2022/01/28 13:06:11 by rrangwan ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_p(unsigned long int n)
{
int ret;
ret = 0;
if (n >= 16)
{
ret += print_p(n / 16);
ret += print_p(n % 16);
}
if (n < 16)
{
if (n < 10)
ret += print_c(n + '0');
else
ret += print_c(n + ('a' - 10));
}
return (ret);
}
int print_h(unsigned int n, char h)
{
int ret;
ret = 0;
if (n >= 16)
{
ret += print_h(n / 16, h);
ret += print_h(n % 16, h);
}
if (n < 16)
{
if (n < 10)
ret += print_c(n + '0');
else
{
if (h == 'x')
ret += print_c(n + ('a' - 10));
else
ret += print_c(n + ('A' - 10));
}
}
return (ret);
}
int print_s(char *s)
{
int ret;
int i;
ret = 0;
i = 0;
if (!s)
s = "(null)";
while (s[i] != '\0')
{
write(1, &s[i], 1);
ret++;
i++;
}
return (ret);
}