-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
60 lines (55 loc) · 1.54 KB
/
ft_printf.c
File metadata and controls
60 lines (55 loc) · 1.54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmanyani <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/30 09:42:29 by mmanyani #+# #+# */
/* Updated: 2024/12/12 21:01:02 by mmanyani ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int looping(const char *format, va_list args, int *total)
{
int i;
i = 0;
while (format[i])
{
if (format[i] == '%')
{
i++;
if (format[i] == '\0')
return (-1);
if (format[i] != '\0')
{
if (format_choice(total, args, format[i]) == -1)
return (-1);
}
}
else
{
if (print_char(format[i]) == -1)
return (-1);
(*total)++;
}
i++;
}
return (*total);
}
int ft_printf(const char *format, ...)
{
int total;
va_list args;
if (format == NULL)
return (-1);
total = 0;
va_start(args, format);
if (looping(format, args, &total) == -1)
{
va_end(args);
return (-1);
}
va_end(args);
return (total);
}