-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
48 lines (44 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alaulom <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/14 17:29:02 by alaulom #+# #+# */
/* Updated: 2016/03/28 12:40:37 by alaulom ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_printf.h"
static void init_env(t_env *env)
{
env->result = 0;
env->i = 0;
}
int ft_printf(const char *format, ...)
{
va_list ap;
t_env env;
t_tab tab;
va_start(ap, format);
init_env(&env);
init_tab(&tab);
while (format[env.i])
{
if (format[env.i] != '%' && format[env.i])
{
ft_putchar(format[env.i]);
env.result++;
}
else if (format[env.i] == '%' && format[env.i + 1])
{
init_flags(&env);
env.i += 1 + ft_whichflags((char*)(format + env.i + 1), &env);
env.result += ft_conv(ap, &env, &tab);
}
else
return (env.result);
env.i++;
}
return (env.result);
}