-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
executable file
·42 lines (37 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snara <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/08 12:54:45 by snara #+# #+# */
/* Updated: 2021/01/20 08:58:50 by snara ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_vdprintf(int fd, const char *fmt, va_list va)
{
t_fmt f;
f.r = 0;
while (fmt && *fmt != '\0' && 0 <= f.r && f.r < INT_MAX)
{
f.r += ft_putsc(fmt, '%', fd);
if (*(fmt += ft_putsc(fmt, '%', -1)) == '%')
{
fmt_parse(&f, fmt, (char**)&fmt, va);
fmt_print(&f, fmt, fd);
fmt++;
}
}
return (f.r < 0 || INT_MAX <= f.r ? -1 : (int)f.r);
}
int ft_printf(const char *fmt, ...)
{
va_list va;
int r;
va_start(va, fmt);
r = ft_vdprintf(1, fmt, va);
va_end(va);
return (r);
}