-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
51 lines (46 loc) · 855 Bytes
/
printf.c
File metadata and controls
51 lines (46 loc) · 855 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
47
48
49
50
#include "main.h"
/**
* _printf - Produces output according to a format.
* @format: The format string.
* @...: Variadic arguments to format.
* Return: The number of characters printed (excluding the null byte).
*/
int _printf(const char *format, ...)
{
va_list ap;
int count = 0;
int (*function)(va_list) = NULL;
va_start(ap, format);
while (*format)
{
if (*format == '%' && *(format + 1) != '%')
{
format++;
function = printf_format(format);
if (*format == '\0')
return (-1);
else if (function == NULL)
{
_putchar(*(format - 1));
_putchar(*format);
count += 2;
}
else
count += function(ap);
}
else if (*format == '%' && *(format + 1) == '%')
{
format++;
_putchar('%');
count++;
}
else
{
_putchar(*format);
count++;
}
format++;
}
va_end(ap);
return (count);
}