-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
38 lines (37 loc) · 737 Bytes
/
printf.c
File metadata and controls
38 lines (37 loc) · 737 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
#include "main.h"
/**
* _printf - emulates printf function
* @format: string
* Return: string length
*/
int _printf(const char *format, ...)
{
va_list list;
int count = 0, i = -1;
int (*f)(va_list);
va_start(list, format);
if (format != NULL)
{
i = 0;
for (; format[count] != '\0'; i++, count++)
{
if (format[count] != '%')
_putchar(format[count]);
else if (format[count] == '%' && format[count + 1] == '\0')
return (-1);
else if (format[count] == '%' && format[count + 1] != '\0')
{
f = pick_func(format[count + 1]);
if (f == NULL)
_putchar(format[count]);
else
{
i = (i + f(list)) - 1;
count++;
}
}
}
}
va_end(list);
return (i);
}