-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
executable file
·62 lines (58 loc) · 1.79 KB
/
ft_printf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sjuery <sjuery@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/15 23:41:52 by sjuery #+# #+# */
/* Updated: 2017/12/06 02:23:52 by sjuery ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_printf.h"
static void initialise_flags(t_printf *prtf)
{
prtf->space = 0;
prtf->sharp = 0;
prtf->zero = 0;
prtf->minus = 0;
prtf->plus = 0;
prtf->size = 0;
prtf->precision = 0;
prtf->precise = 0;
prtf->per_cent = 0;
prtf->hh = 0;
prtf->h = 0;
prtf->ll = 0;
prtf->l = 0;
prtf->j = 0;
prtf->z = 0;
prtf->c = 0;
}
int ft_printf(const char *orgstr, ...)
{
va_list pargs;
t_printf prtf;
t_fpointer fptr;
prtf.ret = 0;
prtf.len = 0;
va_start(pargs, orgstr);
flags_to_converter(&fptr);
while (orgstr[prtf.len])
{
if (orgstr[prtf.len] == '%' && orgstr[prtf.len + 1])
{
initialise_flags(&prtf);
prtf.len += 2 + parse_flags(((char *)orgstr + prtf.len + 1), &prtf);
prtf.ret += parse_input(pargs, &prtf, &fptr);
}
else if (orgstr[prtf.len] != '%' && orgstr[prtf.len])
{
ft_putchar(orgstr[prtf.len++]);
prtf.ret++;
}
else
return (prtf.ret);
}
return (prtf.ret);
}