-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_handle_integer.c
69 lines (61 loc) · 1.69 KB
/
ft_handle_integer.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
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_handle_integer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohaben- <mohaben-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 11:10:49 by mohaben- #+# #+# */
/* Updated: 2024/11/27 11:20:42 by mohaben- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_len_nb(long n)
{
int len;
len = 0;
if (n == 0)
return (1);
while (n != 0)
{
n /= 10;
len++;
}
return (len);
}
int handle_len_integer(long n, t_flags flag)
{
int len;
len = ft_len_nb(n);
if (flag.precision > len)
len = flag.precision;
if (flag.plus || flag.space || (n < 0))
len++;
return (len);
}
void print_loop(char c, int loop, int *count)
{
while (loop-- > 0)
ft_putchar(c, count);
}
void set_sign(long n, int *count, t_flags flag)
{
if ((n < 0))
ft_putchar('-', count);
else if (flag.plus)
ft_putchar('+', count);
else if (flag.space)
ft_putchar(' ', count);
}
void print_nb(long n, int *count)
{
if (n < 0)
n = -n;
if (n >= 10)
{
ft_putnbr(n / 10, count, ft_initializ_flags());
ft_putchar((n % 10) + '0', count);
}
else
ft_putchar(n + '0', count);
}