-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_nbr.c
52 lines (47 loc) · 1.4 KB
/
ft_printf_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_nbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jikarunw <jikarunw@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/16 22:34:49 by jikarunw #+# #+# */
/* Updated: 2023/09/18 17:56:38 by jikarunw ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_print_digits(int num)
{
int digit;
int div;
int temp;
digit = 0;
div = 1;
temp = num;
while (temp >= 10)
{
temp /= 10;
div *= 10;
}
while (div > 0)
{
digit += ft_printf_char('0' + (num / div));
num %= div;
div /= 10;
}
return (digit);
}
int ft_printf_nbr(int num)
{
int digit;
digit = 0;
if (num == INT_MIN)
return (ft_printf_string("-2147483648"));
else if (num < 0)
{
digit += ft_printf_char('-');
num *= -1;
}
digit += ft_print_digits(num);
return (digit);
}