-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_functions2.c
52 lines (47 loc) · 1.57 KB
/
print_functions2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_functions2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tauer <tauer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/15 14:00:28 by tauer #+# #+# */
/* Updated: 2023/11/15 17:07:29 by tauer ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putnbr_base(int nbr, char *base, int *len)
{
int len_base;
long int nbr_cast;
nbr_cast = nbr;
len_base = ft_strlen_printf(base);
if (nbr_cast < 0)
{
ft_putchar_len('-', len);
nbr_cast *= -1;
}
if (nbr_cast > len_base - 1)
{
ft_putnbr_base(nbr_cast / len_base, base, len);
ft_putnbr_base(nbr_cast % len_base, base, len);
}
else
{
ft_putchar_len(base[nbr_cast], len);
}
}
void ft_putnbr_un(unsigned int nbr, char *base, int *len)
{
size_t len_base;
len_base = ft_strlen_printf(base);
if (nbr > len_base - 1)
{
ft_putnbr_ptr(nbr / len_base, base, len);
ft_putnbr_ptr(nbr % len_base, base, len);
}
else
{
ft_putchar_len(base[nbr], len);
}
}