-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
66 lines (61 loc) · 1.82 KB
/
ft_printf.c
File metadata and controls
66 lines (61 loc) · 1.82 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chaydont <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/25 17:51:49 by chaydont #+# #+# */
/* Updated: 2017/12/13 19:34:35 by chaydont ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int functions(va_list ap, t_param flags)
{
char c;
int i;
i = 0;
if (flags.type == '\0')
return (0);
else if (ft_strchr("dDi", flags.type))
return (ft_printi(ap, flags));
else if (flags.type == 's')
return (ft_prints(ap, flags));
else if (ft_strchr("oxXup", flags.type))
return (ft_printu(ap, flags));
else if (flags.type == 'c')
return (ft_printc(ap, flags));
c = flags.type;
if (!flags.minus)
while (i++ < flags.length - 1)
flags.zero ? write(1, "0", 1) : write(1, " ", 1);
ft_putchar(c);
if (flags.minus)
while (i++ < flags.length - 1)
write(1, " ", 1);
return (i);
}
int ft_printf(const char *restrict str, ...)
{
va_list ap;
char *print;
int i;
int j;
t_param flags;
i = 0;
j = 0;
va_start(ap, str);
while (str[i])
{
if (str[i] == '%')
{
i += parsing((char*)str + i + 1, &flags) + 1;
j += functions(ap, flags) - 1;
}
else
ft_putchar(str[i]);
i++;
j++;
}
return (j);
}