forked from MarkosComK/42-Printf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
42 lines (39 loc) · 1.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marsoare <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/27 15:49:01 by marsoare #+# #+# */
/* Updated: 2024/05/09 02:27:47 by marsoare ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printf(char *str, ...)
{
va_list args;
t_flags flags;
int i;
int count;
if (!format || (format[0] == '%' && format[1] == '\0'))
return (-1);
i = 0;
count = 0;
va_start(args, str);
while (str[i])
{
ft_bzero(&flags, sizeof(t_flags));
if (str[i] == '%')
{
i++;
while (ft_memchr("-0.# +", str[i], 6) || ft_isdigit(str[i]))
update_struct(&flags, str, &i);
count += print_format(&flags, str, &i, args);
}
else
count += ft_putchar(str[i++]);
}
va_end(args);
return (count);
}