-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_checks.c
56 lines (51 loc) · 1.61 KB
/
ft_printf_checks.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printf_checks.c :+: :+: */
/* +:+ */
/* By: cwesseli <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/10/31 10:31:00 by cwesseli #+# #+# */
/* Updated: 2022/11/01 15:38:40 by cwesseli ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int check_ident(t_print *list, char c)
{
if (ft_strchr(list->valid_char, c))
return (1);
return (0);
}
int check_input(t_print *list, char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '%' && str [i + 1] == '%')
i++;
else if (str[i] == '%')
{
if (!(str [i + 1]))
return (1);
else if (!(check_ident(list, str[i + 1])))
return (0);
}
i++;
}
return (1);
}
void check_letter(t_print *list, char c)
{
if (c == 'c')
ft_print_char(list);
else if (c == 's')
ft_print_str(list);
else if (c == 'd' || c == 'i' || c == 'u')
ft_print_dec(list, c);
else if (c == 'x' || c == 'X' || c == 'p')
ft_print_hex(list, c);
else if (c == '%')
list->len += write(1, "%", 1);
return ;
}