-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printunsigned.c
More file actions
54 lines (48 loc) · 1.4 KB
/
ft_printunsigned.c
File metadata and controls
54 lines (48 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printunsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abillote <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/29 13:42:20 by abillote #+# #+# */
/* Updated: 2023/11/29 14:48:11 by abillote ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_count_digit_unsigned(unsigned int nb)
{
int count;
int weight;
count = 0;
weight = 1;
while (nb > 9)
{
nb /= 10;
count += 1;
weight *= 10;
}
count += 1;
return (count);
}
void ft_putunsigned(unsigned int nb)
{
if (nb < 10)
{
nb += '0';
write(1, &nb, 1);
}
else if (nb > 0)
{
ft_putunsigned(nb / 10);
ft_putunsigned(nb % 10);
}
}
int ft_printunsigned(unsigned int nb)
{
int nb_char;
nb_char = 0;
ft_putunsigned(nb);
nb_char = ft_count_digit_unsigned(nb);
return (nb_char);
}