-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
54 lines (50 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asoudani <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 10:14:53 by asoudani #+# #+# */
/* Updated: 2024/11/17 21:20:12 by asoudani ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int while_loop(const char *form, int *count, va_list args, int *err)
{
while (*form)
{
if (*form == '%' && check_char(*(form + 1)) == 1)
{
form = formats(form, args, count, err);
if (*err == -1)
return (-1);
form++;
}
else if (*form != '%')
{
if (ft_putchar_fd(*form, 1, count) == -1)
{
va_end(args);
return (-1);
}
}
form++;
}
return (*count);
}
int ft_printf(const char *form, ...)
{
int count;
va_list args;
int err;
if (!form)
return (0);
va_start(args, form);
count = 0;
count = while_loop(form, &count, args, &err);
if (err == -1)
return (-1);
va_end(args);
return (count);
}