-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_printf.c
More file actions
50 lines (48 loc) · 776 Bytes
/
_printf.c
File metadata and controls
50 lines (48 loc) · 776 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 - print anything with formating
*@format: pointer
* Return: On success.
*/
int _printf(char *format, ...)
{
int written = 0, (*structype)(char *, va_list);
char q[3];
va_list pa;
if (format == NULL)
return (-1);
q[2] = '\0';
va_start(pa, format);
_putchar(-1);
while (format[0])
{
if (format[0] == '%')
{
structype = driver(format);
if (structype)
{
q[0] = '%';
q[1] = format[1];
written += structype(q, pa);
}
else if (format[1] != '\0')
{
written += _putchar('%');
written += _putchar(format[1]);
}
else
{
written += _putchar('%');
break;
}
format += 2;
}
else
{
written += _putchar(format[0]);
format++;
}
}
_putchar(-2);
return (written);
}