-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_unbr.c
47 lines (42 loc) · 1.36 KB
/
ft_print_unbr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_unbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalbano <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 13:09:14 by dalbano #+# #+# */
/* Updated: 2024/11/03 12:36:11 by dalbano ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int nbrlen(unsigned long n)
{
int len;
len = 0;
if (n == 0)
len = 1;
while (n != 0)
{
len++;
n /= 10;
}
return (len);
}
static int ft_putnbr_ufd_printf(unsigned long n, int fd)
{
if (n >= 10)
{
if (ft_putnbr_ufd_printf(n / 10, fd) == -1)
return (-1);
}
if (ft_putchar_fd_printf(n % 10 + '0', fd) == -1)
return (-1);
return (0);
}
int ft_print_unbr(unsigned long n)
{
if (ft_putnbr_ufd_printf(n, 1) == -1)
return (-1);
return (nbrlen(n));
}