-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilis_int.c
More file actions
89 lines (78 loc) · 1.67 KB
/
utilis_int.c
File metadata and controls
89 lines (78 loc) · 1.67 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilis_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abkssiba <abkssiba@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/11 12:14:40 by abkssiba #+# #+# */
/* Updated: 2019/12/13 17:24:34 by abkssiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int get_u_digits(unsigned int n)
{
int len;
unsigned int nb;
len = 0;
nb = n;
while (nb > 9)
{
nb /= 10;
len++;
}
if (nb <= 9)
len++;
return (len);
}
int get_int_digits(int n)
{
int len;
unsigned int nb;
len = 0;
if (n < 0)
{
len++;
nb = -n;
}
else
nb = n;
while (nb > 9)
{
nb /= 10;
len++;
}
if (nb <= 9)
len++;
return (len);
}
int apply_width_int(int width)
{
int count;
count = 0;
while (count < width)
{
ft_putchar_fd(' ', 1);
count++;
}
return (count);
}
int apply_zero_int(int width)
{
int count;
count = 0;
while (count < width)
{
ft_putchar_fd('0', 1);
count++;
}
return (count);
}
void ft_putnbr_u(unsigned int n)
{
unsigned int nb;
nb = n;
if (nb > 9)
ft_putnbr_u(nb / 10);
ft_putchar(nb % 10 + 48);
}