This repository has been archived by the owner on Nov 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
64 lines (57 loc) · 1.89 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
63
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 22:27:23 by mchen #+# #+# */
/* Updated: 2017/02/21 20:05:08 by mchen ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_printf.h"
int ft_vfdprintf(int fd, const char *format, va_list a_list)
{
t_placehold *p;
const char *e;
size_t count;
count = 0;
if (format)
{
p = malloc(sizeof(*p));
e = format;
while (*format)
{
if (*format == '%')
{
e = format + 1;
eval_fields(p, &e, a_list);
count += print_eval(fd, p, a_list, count);
format = e;
}
else
count += ft_putchar_fd(*(format), fd);
format += *format ? 1 : 0;
}
free(p);
}
return (count);
}
int ft_fdprintf(int fd, const char *format, ...)
{
va_list a_list;
size_t count;
va_start(a_list, format);
count = ft_vfdprintf(fd, format, a_list);
va_end(a_list);
return (count);
}
int ft_printf(const char *format, ...)
{
va_list a_list;
size_t count;
va_start(a_list, format);
count = ft_vfdprintf(1, format, a_list);
va_end(a_list);
return (count);
}