-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf_tool1.c
More file actions
57 lines (53 loc) · 1.54 KB
/
printf_tool1.c
File metadata and controls
57 lines (53 loc) · 1.54 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printf_tool1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zrdouane <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/13 18:15:12 by zrdouane #+# #+# */
/* Updated: 2021/12/13 18:15:13 by zrdouane ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_puthex(unsigned int n, const char *base, int *len)
{
if (n < 16)
ft_putchar(base[n], len);
else
{
ft_puthex(n / 16, base, len);
ft_putchar(base[n % 16], len);
}
}
void ft_putnbr_u(unsigned int n, int *len)
{
if (n >= 10)
{
ft_putnbr_u(n / 10, len);
ft_putchar((n % 10) + '0', len);
}
else
ft_putchar(n + '0', len);
}
void ft_putnbr(int c, int *len)
{
if (c == -2147483648)
{
write(1, "-2147483648", 11);
*len = *len + 11;
return ;
}
else if (c < 0)
{
ft_putchar('-', len);
c *= -1;
}
if (c >= 0 && c < 10)
ft_putchar(c + '0', len);
else
{
ft_putnbr(c / 10, len);
ft_putchar((c % 10) + '0', len);
}
}