-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_printf.c
More file actions
41 lines (39 loc) · 769 Bytes
/
_printf.c
File metadata and controls
41 lines (39 loc) · 769 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
#include "holberton.h"
/**
* _printf - format and print data
* @format: string to print
* Return: length, or -1 in case of failure
*/
int _printf(const char *format, ...)
{
va_list call;
unsigned int i, length = 0;
va_start(call, format);
if (!format || (format[0] == '%' && format[1] == '\0'))
return (-1);
for (i = 0; format[i] != '\0'; i++) /*runs along the chain*/
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{ _putchar('%');
i = i + 1;
length++;
}
else if (mod_character_s(format, i + 1) != '\0')
{ length += mod_character_s(format, i + 1)(call);
i = i + 1;
}
else
{ _putchar(format[i]);
length++;
}
}
else
{ _putchar(format[i]);
length++;
}
}
va_end(call);
return (length);
}