forked from mikialx/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_printf.c
39 lines (32 loc) · 773 Bytes
/
_printf.c
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
#include "main.h"
/**
* _printf - clone of the function printf in stdio.h
* @format: the string to be printed along with format specifiers preceded by %
*
* Return: the number of characters printed
*/
int _printf(const char *format, ...)
{
int char_count = 0; /* Total number of chars printed to stdout */
va_list ap; /* Contains the list of arguments passed after format */
int i; /* Used to loop through all characters in format */
va_start(ap, format);
if (format == NULL)
return (-1);
for (i = 0; format[i] != 0; i++)
{
if (format[i] != '%')
{
_putchar(format[i]);
char_count++;
continue;
}
if (format[i + 1] == '\0')
{
return (-1);
}
char_count += get_printing_func(format[i + 1], &ap);
i++;
}
return (char_count);
}