-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_printf.c
45 lines (39 loc) · 852 Bytes
/
_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
#include "main.h"
/**
* _printf - a function that produces output according to a format.
*
* @format: a list of types of arguments passed to the function.
*
* Return: the number of characters printed.
*/
int _printf(const char *format, ...)
{
int printed_chars = 0;
va_list args;
char *form = (char *)format;
va_start(args, format);
if (!format || (format[0] == '%' && !format[1]))
return (-1);
if (format[0] == '%' && format[1] == ' ' && !format[2])
return (-1);
while (form && *form)
{
if (*form == '%')
{
form++;
if (specifier(form) || *form == '%')
printed_chars += get_func(form, args);
if (!specifier(form))
{
--form;
printed_chars += fill_buffer(*form);
}
}
else
printed_chars += fill_buffer(*form);
form++;
}
fill_buffer(CLEAR_BUFFER);
va_end(args);
return (printed_chars);
}