-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_uint.c
62 lines (56 loc) · 1.7 KB
/
ft_print_uint.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_uint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amahla <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:00:34 by amahla #+# #+# */
/* Updated: 2022/05/06 11:22:19 by amahla ### ########.fr */
/* */
/* ************************************************************************** */
#include"ft_printf.h"
int init_uflags(t_flag *fg)
{
fg->hash = 0;
fg->plus = 0;
fg->space = 0;
if (fg->minus)
fg->zero = 0;
return (0);
}
void ft_fill_uint(t_flag *fg, char *str, int nb)
{
int size;
if (fg->minus)
{
if (start_zero(str, fg->nbrlen) == -1)
size = 0;
else
size = start_zero(str, fg->nbrlen);
}
else
size = ft_strlen(str) - fg->nbrlen;
ft_utoa(nb, str, size);
}
char *ft_printf_uint(t_flag *fg, unsigned int nb)
{
char *str;
int option;
str = NULL;
fg->nbrlen = ulen(nb);
option = init_uflags(fg);
if (nb == 0 && fg->point && !(fg->precision))
fg->nbrlen = 0;
str = ft_flag(fg, option);
if (!str && fg->nbrlen)
{
str = ft_calloc(fg->nbrlen + 1, sizeof(char));
if (!str)
return (NULL);
ft_memset(str, ' ', fg->nbrlen);
}
if (fg->nbrlen)
ft_fill_uint(fg, str, nb);
return (str);
}