-
Notifications
You must be signed in to change notification settings - Fork 0
/
put_uint.c
60 lines (52 loc) · 1.52 KB
/
put_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
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* put_uint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tayeo <tayeo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 15:33:37 by tayeo #+# #+# */
/* Updated: 2022/07/08 15:44:59 by tayeo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int numlen(unsigned int nb);
static unsigned int power(unsigned int n);
int put_uint(unsigned int num)
{
int index;
char numchar;
numchar = 0;
index = numlen(num);
while (index >= 0)
{
numchar = ((num / power(index)) % 10) + '0';
write(1, &numchar, 1);
index--;
}
return (numlen(num) + 1);
}
static int numlen(unsigned int nb)
{
int len;
len = 0;
while ((nb / 10) > 0)
{
nb /= 10;
len ++;
}
return (len);
}
static unsigned int power(unsigned int n)
{
unsigned int power;
unsigned int index;
power = 1;
index = 0;
while (index < n)
{
power = power * 10;
index++;
}
return (power);
}