-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_processor.c
36 lines (34 loc) · 1.69 KB
/
ft_processor.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_processor.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mrosie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/19 12:38:50 by mrosie #+# #+# */
/* Updated: 2020/11/25 13:27:52 by mrosie ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_processor(char type, t_spec *sp, va_list ar)
{
if (type == 'c')
return (ft_print_char(*sp, (char)va_arg(ar, int)));
else if (type == 's')
return (ft_print_string(*sp, va_arg(ar, char *)));
else if (type == 'p')
return (ft_print_pointer(*sp, va_arg(ar, unsigned long)));
else if (type == 'd' || type == 'i')
return (ft_print_number(*sp, va_arg(ar, int), 10, 0));
else if (type == 'u')
return (ft_print_number(*sp, va_arg(ar, unsigned int), 10, 0));
else if (type == 'x')
return (ft_print_number(*sp, va_arg(ar, unsigned int), 16, 0));
else if (type == 'X')
return (ft_print_number(*sp, va_arg(ar, unsigned int), 16, 1));
else if (type == 'o')
return (ft_print_number(*sp, va_arg(ar, unsigned int), 8, 0));
else if (type == '%')
return (ft_print_char(*sp, '%'));
return (-1);
}