-
Notifications
You must be signed in to change notification settings - Fork 1
/
_printf.c
50 lines (46 loc) · 816 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
46
47
48
49
50
#include "_printf.h"
/**
* _printf - This function works like printf
* @format: Format string
*
* Return: Number of printed characters
*/
int _printf(const char *format, ...)
{
int (*print)(va_list list, ...);
int numChar = 0;
va_list list;
if (!format || (format[0] == '\0') || (format[0] == '%' && format[1] == '\0'))
return (-1);
va_start(list, format);
while (*format)
{
if (*format == '\\' && *(format + 1) == '%')
{
_putchar('%');
format++;
continue;
}
if (*format != '%')
{
numChar += _putchar(*format);
format++;
continue;
}
if (*format == '%')
{
format++;
print = specifier(*format);
if (print == NULL)
{
_putchar(*format);
numChar++;
continue;
}
}
numChar += print(list);
format++;
}
va_end(list);
return (numChar);
}