-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnmbr.c
49 lines (44 loc) · 1.39 KB
/
ft_putnmbr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnmbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aceauses <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 19:38:03 by aceauses #+# #+# */
/* Updated: 2023/04/28 15:57:01 by aceauses ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_long_base_len(long int index, size_t base)
{
size_t i;
i = 1;
while (index >= (long int)base)
{
index = index / base;
i++;
}
return (i);
}
int ft_putnmbr(long int n)
{
char *base;
int nmbr_len;
base = "0123456789";
nmbr_len = 0;
if (n < 0)
{
write(1, "-", 1);
nmbr_len += ft_putnmbr(-n);
}
else if (n >= 10)
{
ft_putnmbr(n / 10);
ft_putnmbr(n % 10);
}
else
write (1, &base[n], 1);
nmbr_len += ft_long_base_len(n, ft_strlen_printf(base));
return (nmbr_len);
}