-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_d.c
More file actions
54 lines (49 loc) · 1.32 KB
/
print_d.c
File metadata and controls
54 lines (49 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cmachado <cmachado@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/06 21:33:34 by cmachado #+# #+# */
/* Updated: 2022/04/16 22:02:10 by cmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int w_nbr(int n, int cnt)
{
char c;
if (n == -2147483648)
{
write(1, "-2", 2);
n = 147483648;
}
else if (n < 0)
{
write(1, "-", 1);
n *= -1;
}
if (n > 9)
{
cnt += w_nbr(n / 10, cnt);
w_nbr(n % 10, cnt);
}
else
{
c = n + 48;
write(1, &c, 1);
}
return (cnt);
}
int print_d(int n)
{
int cnt;
cnt = w_nbr(n, 1);
if (n < 0)
{
cnt += 1;
if (n == -2147483648)
cnt += 1;
}
return (cnt);
}