-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifint.c
59 lines (53 loc) · 1.35 KB
/
ifint.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* numlength.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agraetz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/31 11:05:36 by agraetz #+# #+# */
/* Updated: 2022/03/31 12:14:40 by agraetz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void makechar(size_t n)
{
if (n > 9)
{
makechar(n / 10);
makechar(n % 10);
}
if (n < 10)
{
ft_putchar_fd(n + 48, 1);
}
}
int numlength(size_t n, int base)
{
int len;
len = 0;
if (!n)
{
return (1);
}
while (n > 0)
{
n /= base;
len++;
}
return (len);
}
int ifint(long long int n)
{
int count;
count = 0;
if (n < 0)
{
ft_putchar_fd('-', 1);
n = -n;
count++;
}
makechar(n);
count += numlength(n, 10);
return (count);
}