-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
executable file
·66 lines (58 loc) · 1.67 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
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmakwakw <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/30 17:59:49 by mmakwakw #+# #+# */
/* Updated: 2017/11/30 18:06:06 by mmakwakw ### ########.fr */
/* */
/* ************************************************************************** */
# include "ft_printf.h"
static void ft_process(char *format, va_list ap)
{
char flag;
int i;
i = 0;
while (format[i])
{
if (format[i] == '%')
{
i++;
flag = ft_getflag(format[i]);
i = ft_output(format, flag, ap, i);
}
else if (format[i] != '\0')
ft_putchar(format[i]);
i++;
}
}
static void ft_input(char *format, va_list ap)
{
int ret;
ret = ft_checkmod(format);
if (ret == 1)
ft_process(format, ap);
else if (ret == 2)
ft_mod(format);
else
{
if (ret < 0)
ft_putstr(format);
}
}
int ft_output(char *format, char flag, va_list ap, int i)
{
i = ft_skip(format, i);
ft_speciftypeini(format, format[i], flag, ap);
return (i);
}
int ft_printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
ft_input((char *)format, ap);
va_end(ap);
return (0);
}