-
Notifications
You must be signed in to change notification settings - Fork 0
/
_printf.c
52 lines (47 loc) · 812 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
51
52
#include "main.h"
/**
* _printf - function that produces output according to a format.
* @format: char.
* @...: other variables.
* Return: int.
*/
int _printf(const char *format, ...)
{
int (*_fl)(va_list);
int i = 0, c = 0;
va_list fn;
if (format != NULL)
{
va_start(fn, format);
if (format[0] == '%' && format[1] == '\0')
return (-1);
while (format[i] != '\0' && format != NULL)
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{
c += _putchar(format[i]);
i = i + 2;
}
else
{
_fl = fl(format[i + 1]);
if (_fl)
c += _fl(fn);
else
c = _putchar(format[i]) + _putchar(format[i + 1]);
i = i + 2;
}
}
else
{
c += _putchar(format[i]), i++;
}
}
va_end(fn);
return (c);
}
else
return (-1);
}