-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
71 lines (64 loc) · 1.99 KB
/
Copy pathft_printf.c
File metadata and controls
71 lines (64 loc) · 1.99 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
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpetsoan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/18 06:56:54 by lpetsoan #+# #+# */
/* Updated: 2019/07/12 12:58:21 by lpetsoan ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printf(char const *f, ...)
{
va_list list;
va_start(list, f);
while (*f)
{
if (*f == '%')
{
f++;
if (parse_spec(&f, list) == -1)
return (-1);
}
else
{
ft_putchar(*f);
f++;
}
}
return (0);
}
/*
* This function takes a list and stores the flags in to the list and prints
* the value on the screen
*/
int parse_spec(char const **f, va_list list)
{
static t_specifier spec;
static char id;
if (get_id(*f, &id) == -1)
return (-1);
spec.field_width = NULL;
spec.max_width = NULL;
spec.flag = 0;
if (get_format((char **)f, &spec) == -1)
return (-1);
print_specifier(id, &spec, list);
(*f)++;
return (0);
}
void print_specifier(const char id, t_specifier *spec, va_list list)
{
if (id == 'd' || id == 'D')
print_type(spec, ft_itoa(va_arg(list, int)));
else if (id == 's' || id == 'S')
print_type(spec, va_arg(list, char *));
else if (id == 'f' || id == 'F')
print_float(spec, va_arg(list, double));
else if (id == 'x' || id == 'X')
print_conv(spec, va_arg(list, int), 16);
else if (id == 'o' || id == 'O')
print_conv(spec, va_arg(list, int), 8);
}