-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
48 lines (43 loc) · 1.47 KB
/
Copy pathft_printf.c
File metadata and controls
48 lines (43 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: viferrei <viferrei@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 15:48:08 by viferrei #+# #+# */
/* Updated: 2021/11/08 20:42:30 by viferrei ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printf(const char *format, ...)
{
va_list arg;
size_t len;
va_start(arg, format);
len = ft_vprintf(format, arg);
va_end(arg);
return (len);
}
int ft_vprintf(const char *format, va_list arg)
{
size_t len;
t_format *fmt;
t_holder *holder;
fmt = ft_init_format(format, arg);
holder = ft_init_holder();
while (fmt->format[fmt->index] != '\0')
{
if (fmt->format[fmt->index] == '%')
ft_placeholder(fmt, holder);
else
{
fmt->len += write(1, &fmt->format[fmt->index], 1);
fmt->index++;
}
}
len = fmt->len;
free(fmt);
free(holder);
return (len);
}