-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils4.c
97 lines (89 loc) · 2.55 KB
/
ft_printf_utils4.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebassi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/01 16:44:05 by ebassi #+# #+# */
/* Updated: 2022/02/02 14:03:11 by ebassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_handle_integer_else_2(int arg, int len, int tmp, t_params *my_struct)
{
char *arg_str;
arg_str = ft_itoa(arg);
if (arg < 0)
len += ft_putchar('-');
while (tmp-- > (int)ft_strlen(arg_str))
len += write(1, "0", 1);
ft_putnbr2(arg, my_struct);
free(arg_str);
return (len);
}
int ft_others(int index, char *input, t_params *my_struct)
{
if (input[index] == '+')
{
my_struct->plus = 1;
index++;
}
else if (input[index] == '#')
{
my_struct->hash = 1;
index++;
}
else if (input[index] == ' ')
{
my_struct->space = 1;
index++;
}
else
index++;
return (index);
}
int ft_point(int index, t_params *my_struct, char *input, int *nbr)
{
index++;
my_struct->point = 1;
while (ft_isdigit(input[index]))
{
*nbr = *nbr * 10 + input[index] - '0';
index++;
}
return (index);
}
int ft_zero(int index, t_params *my_struct, char *input, int *nbr)
{
my_struct->zeros = 1;
while (ft_isdigit(input[index]))
{
*nbr = *nbr * 10 + input[index] - '0';
index++;
}
return (index);
}
int ft_handle_while(char *input, t_params *my_struct, int nbr, va_list args)
{
int index;
int len;
index = 0;
len = 0;
while (input[index] && !(ft_iscommand(input[index])))
{
nbr = 0;
if (input[index] == '-')
index = ft_minus(index, input, nbr, my_struct);
else if (input[index] == '0')
index = ft_zero(index, my_struct, input, &nbr);
else if (input[index] >= '1' && input[index] <= '9')
index = ft_width(index, input, nbr, my_struct);
else if (input[index] == '.')
index = ft_point(index, my_struct, input, &nbr);
else
index = ft_others(index, input, my_struct);
}
len += print_value(input[index], args, my_struct, nbr);
return (len);
}