-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
48 lines (44 loc) · 1.57 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: eouhrich <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 10:38:55 by eouhrich #+# #+# */
/* Updated: 2023/11/28 10:38:57 by eouhrich ### ########.fr */
/* */
/* ************************************************************************** */
#include"ft_printf.h"
void flag_checker(const char *format, int *i, va_list *args, int *count)
{
if (ft_strchr("cspdiuxX%", format[*i + 1]) != NULL)
*count += mendatory_flag(format[*i + 1], args);
else if (ft_strchr(" +#", format[*i + 1]) != NULL)
bonus_flags(format, i, args, count);
else if (format[*i + 1])
*count += ft_putchar(format[*i + 1]);
}
int ft_printf(const char *format, ...)
{
int i;
va_list args;
int count;
va_start(args, format);
i = 0;
count = 0;
while (format[i] != '\0')
{
if (format[i] == '%')
{
flag_checker(format, &i, &args, &count);
i++;
}
else
count += ft_putchar(format[i]);
if (format[i] != '\0')
i++;
}
va_end(args);
return (count);
}