-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_put_nbr.c
56 lines (50 loc) · 1.01 KB
/
my_put_nbr.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
/*
** EPITECH PROJECT, 2023
** my_put_nbr
** File description:
** Display all the possible values of an int
*/
#include "includes/my_printf.h"
int check_minus(int *nb)
{
if (*nb < 0) {
if (*nb == -2147483648) {
my_put_nbr(-214748364);
my_putchar('8');
return (11);
}
*nb = -(*nb);
my_putchar('-');
return (1);
}
return (0);
}
int my_int_len(int nb)
{
int len = 0;
if (nb == 0) {
return (1);
}
while (nb != 0) {
nb /= 10;
len += 1;
}
return (len);
}
int my_put_nbr(int nb)
{
int divided = 1;
int result_nb = 0;
int len = 0;
len = len + check_minus(&nb);
if (len == 11)
return (11);
for (int i = 0; i < (my_int_len(nb) - 1); i++)
divided = divided * 10;
for (int j = 0; j < my_int_len(nb); j++ ) {
result_nb = (nb / divided) % 10;
divided = divided / 10;
my_putchar(result_nb + 48);
}
return (my_int_len(nb) + len);
}