-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_helper.c
94 lines (84 loc) · 1.83 KB
/
ft_printf_helper.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wboutzou <wboutzou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/02 16:37:49 by wboutzou #+# #+# */
/* Updated: 2021/12/02 21:53:20 by wboutzou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int fthexa(unsigned int a, char *base, int b)
{
int count;
count = 0;
if (a < (unsigned int)b)
{
count += ft_putchar(base[a]);
}
else
{
count += fthexa(a / b, base, b);
count += ft_putchar(base[a % b]);
}
return (count);
}
int ft_phexa(unsigned long long a)
{
int count;
char *base;
base = "0123456789abcdef";
count = 0;
if (a < 16)
{
count += ft_putchar(base[a]);
}
else
{
count += ft_phexa(a / 16);
count += ft_putchar(base[a % 16]);
}
return (count);
}
int ft_putstr(char *str)
{
int i;
i = 0;
if (!str)
return (ft_putstr("(null)"));
while (str[i])
{
ft_putchar(str[i]);
i++;
}
return (i);
}
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_putnbr(int a)
{
int i;
long nb;
i = 0;
nb = (long)a;
if (nb < 0)
{
i += ft_putchar('-');
nb = nb * -1;
}
if (nb >= 10)
{
i += ft_putnbr(nb / 10);
i += ft_putnbr(nb % 10);
}
else
{
i += ft_putchar(nb + '0');
}
return (i);
}