-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
executable file
·70 lines (62 loc) · 1.19 KB
/
ft_printf.c
File metadata and controls
executable file
·70 lines (62 loc) · 1.19 KB
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
#include "ft_printf.h"
int printed_char_counter(int add)
{
static int counter = 0;
counter = counter + add;
return (counter);
}
static void check_print(char *index, va_list list, t_arg *arg)
{
check_type_copy(*index, list, arg);
print_t_arg(arg, index);
}
void string_reader(char *str, va_list list, t_arg *arg)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '%')
{
i++;
if (ft_strchr((const char *)FLAGS, str[i]))
{
while (ft_strchr((const char *)FLAGS, str[i]))
i = i + check_flag(&str[i], list, arg);
if (str[i] == '$')
i++;
check_print(&str[i], list, arg);
}
else
check_print(&str[i], list, arg);
}
else
putchar_count(str[i], 1);
i++;
}
}
void init_arg(t_arg *arg)
{
arg->min_width_on = '0';
arg->minus_flag_on = '0';
arg->precision_on = '0';
arg->zero_flag_on = '0';
arg->precision_minus = '0';
}
int ft_printf(const char *str, ...)
{
va_list list;
t_arg *arg_ptr;
t_arg arg;
int result;
arg_ptr = &arg;
if (!str)
return (0);
va_start(list, str);
init_arg(arg_ptr);
string_reader((char *)str, list, arg_ptr);
va_end(list);
result = printed_char_counter(0);
printed_char_counter(result * (-1));
return (result);
}