-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_printf.c
More file actions
49 lines (46 loc) · 680 Bytes
/
_printf.c
File metadata and controls
49 lines (46 loc) · 680 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 "holberton.h"
#include <stdio.h>
/**
* _printf - our own printf.
* @format: a char pointer named format.
*
* Return: an int
*/
int _printf(const char *format, ...)
{
va_list args;
unsigned int j = 0;
int g = 0;
int count = 0;
va_start(args, format);
if (format == NULL)
{
return (-1);
}
if (format[j] == '%' && format[j + 1] == '\0')
{
return (-1);
}
while (format[j] != '\0')
{
if (format[j] != '%')
{
_putchar(format[j]);
count++;
}
else
{
j++;
g = printf_get_function(format + j)(args);
if (g == -1)
{
_putchar('%');
_putchar(format[j]);
g += 2;
}
}
j++;
}
va_end(args);
return (count + g);
}