-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
67 lines (59 loc) · 1.54 KB
/
utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: macelik <macelik@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/03 12:48:00 by macelik #+# #+# */
/* Updated: 2023/03/07 17:26:55 by macelik ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_base(long n, int len, char *base)
{
int i;
i = 0;
if (n < 0)
{
i += write(1, "-", 1);
n *= -1;
}
if (n >= len)
{
i += print_base(n / len, len, base);
i += print_base(n % len, len, base);
}
else
i += write(1, &base[n], 1);
return (i);
}
int print_chr(int n)
{
write(1, &n, 1);
return (1);
}
int print_str(char *n)
{
int i;
if (!n)
return (print_str("(null)"));
i = 0;
while (n[i])
{
i += write(1, &n[i], 1);
}
return (i);
}
int p_flag(unsigned long n)
{
int i;
i = 0;
if (n >= 16)
i += p_flag(n / 16);
if ((n % 16) < 10)
i += print_chr((n % 16) + '0');
else
i += print_chr((n % 16) + 87);
return (i);
}