This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_print_unsigned.c
65 lines (58 loc) · 1.92 KB
/
ft_print_unsigned.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_unsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/17 15:15:24 by mcombeau #+# #+# */
/* Updated: 2021/12/17 15:42:11 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_u(char *nbstr, t_flags flags)
{
int count;
count = 0;
if (flags.precision >= 0)
count += ft_pad_width(flags.precision - 1,
ft_strlen(nbstr) - 1, 1);
count += ft_print_s(nbstr);
return (count);
}
int ft_print_unint(char *nbstr, t_flags flags)
{
int count;
count = 0;
if (flags.left == 1)
count += ft_print_u(nbstr, flags);
if (flags.precision >= 0 && (size_t)flags.precision < ft_strlen(nbstr))
flags.precision = ft_strlen(nbstr);
if (flags.precision >= 0)
{
flags.width -= flags.precision;
count += ft_pad_width(flags.width, 0, 0);
}
else
count += ft_pad_width(flags.width, ft_strlen(nbstr), flags.zero);
if (flags.left == 0)
count += ft_print_u(nbstr, flags);
return (count);
}
int ft_print_unsigned(unsigned n, t_flags flags)
{
char *nbstr;
int count;
count = 0;
if (flags.precision == 0 && n == 0)
{
count += ft_pad_width(flags.width, 0, 0);
return (count);
}
nbstr = ft_printf_utoa(n);
if (!nbstr)
return (0);
count += ft_print_unint(nbstr, flags);
free(nbstr);
return (count);
}