-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_uint.c
58 lines (52 loc) · 1.49 KB
/
print_uint.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_uint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 17:08:36 by sde-silv #+# #+# */
/* Updated: 2023/07/12 17:08:39 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
static void ft_putchar_fd(char c, int fd)
{
write (fd, &c, 1);
}
*/
static void ft_putunbr_fd(unsigned long int n, int fd)
{
if (n > 9)
{
ft_putunbr_fd(n / 10, fd);
ft_putchar_fd(n % 10 + '0', fd);
}
else
ft_putchar_fd(n + '0', fd);
}
static int count_digits(unsigned int n)
{
int count;
unsigned long int nb;
count = 0;
nb = n;
if (nb == 0)
return (1);
while (nb)
{
nb = nb / 10;
count ++;
}
return (count);
}
int print_uint(unsigned int next)
{
int digits;
unsigned long int nbr;
nbr = next;
digits = count_digits(nbr);
ft_putunbr_fd(nbr, 1);
return (digits);
}