-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
45 lines (43 loc) · 791 Bytes
/
_printf.c
File metadata and controls
45 lines (43 loc) · 791 Bytes
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 - print everything
*
* @format: specifiers for data types
* Return: int
*/
int _printf(const char *format, ...)
{
int (*print_f)(va_list, flags_f *);
const char *c;
va_list args;
flags_f flags = {0, 0, 0};
int count = 0;
va_start(args, format);
if (!format || (format[0] == '%' && !format[1]))
return (-1);
if (format[0] == '%' && format[1] == ' ' && !format[2])
return (-1);
for (c = format; *c; c++)
{
if (*c == '%')
{
c++;
if (*c == '%')
{
count += _putchar('%');
continue;
}
while (get_flag(*c, &flags))
c++;
print_f = get_print(*c);
count += (print_f)
? print_f(args, &flags)
: _printf("%%%c", *c);
}
else
count += _putchar(*c);
}
_putchar(-1);
va_end(args);
return (count);
}