-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
49 lines (42 loc) · 779 Bytes
/
_printf.c
File metadata and controls
49 lines (42 loc) · 779 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
#include "main.h"
/**
* _printf - prints anything
* @format: the format to print
* Return: number of char printed
*/
int _printf(const char *format, ...)
{
int count = -1, i;
if (format != NULL)
{
va_list args;
int (*f)(va_list);
va_start(args, format);
if (format[0] == '%' && format[1] == '\0')
return (-1);
count = 0;
for (i = 0; format[i] != '\0'; i++)
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{
count += _putchar(format[i]);
i++;
}
else if (format[i + 1] != '\0')
{
f = get_specifier(format[i + 1]);
count += (f ? f(args) : _putchar(format[i]) + _putchar(format[i + 1]));
i++;
}
}
else
{
count += _putchar(format[i]);
}
}
va_end(args);
}
return (count);
}