-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
executable file
·46 lines (43 loc) · 847 Bytes
/
Copy path_printf.c
File metadata and controls
executable file
·46 lines (43 loc) · 847 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
46
#include "main.h"
/**
* _printf - produces output according to a format
* @format: format of string
* Description: this function will produce output according to a format
* Return: length of string
*/
int _printf(const char *format, ...)
{
int (*pfunc)(va_list, flags_t *);
const char *p;
va_list arguments;
flags_t flags = {0, 0, 0};
register int counter = 0;
va_start(arguments, format);
if (!format || (format[0] == '%' && !format[1]))
return (-1);
if (format[0] == '%' && format[1] == ' ' && !format[2])
return (-1);
for (p = format; *p; p++)
{
if (*p == '%')
{
p++;
if (*p == '%')
{
counter += _putchar('%');
continue;
}
while (get_flag(*p, &flags))
p++;
pfunc = get_print(*p);
counter += (pfunc)
? pfunc(arguments, &flags)
: _printf("%%%c", *p);
}
else
counter += _putchar(*p);
}
_putchar(-1);
va_end(arguments);
return (counter);
}