-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
46 lines (43 loc) · 709 Bytes
/
Copy pathprintf.c
File metadata and controls
46 lines (43 loc) · 709 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
#include "holberton.h"
/**
* _printf - function.
* @format: lista de argumentos pasados
* Return: Always 0.
*/
int _printf(const char *format, ...)
{
va_list valist;
unsigned int i = 0, j = 0;
va_start(valist, format);
if (!format || (format[0] == '%' && format[1] == '\0'))
return (-1);
for (i = 0; format != NULL && format[i] != '\0'; i++)
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{
_putchar('%');
j++;
i++;
}
else if (_typedata(format, i + 1) != NULL)
{
j += _typedata(format, i + 1)(valist);
i++;
}
else
{
_putchar(format[i]);
j++;
}
}
else
{
_putchar(format[i]);
j++;
}
}
va_end(valist);
return (j);
}