-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_d.c
55 lines (51 loc) · 1.67 KB
/
ft_printf_d.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: estettle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 14:26:11 by estettle #+# #+# */
/* Updated: 2024/10/27 21:06:49 by estettle ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/**
* @brief Calculates the number of digits of an integer.
*
* @note Minus signs are considered as an additional digit.
*
* @param nb The integer to process.
* @return Returns the number of digits calculated.
*/
static int get_int_len(int nb)
{
int divider;
int digit_count;
if (nb == -2147483648)
return (11);
divider = 1;
digit_count = 1;
if (nb < 0)
{
digit_count++;
nb = -nb;
}
while ((nb / divider) >= 10)
{
divider *= 10;
digit_count++;
}
return (digit_count);
}
/**
* @brief Prints a decimal integer and counts the number of bytes written.
*
* @param nb The integer to print.
* @param count A pointer to the number of bytes written by ft_printf() so far.
*/
void process_dec(int nb, int *count)
{
ft_putnbr_fd(nb, 1);
*count += get_int_len(nb);
}