-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintf.c
49 lines (46 loc) · 869 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
40
41
42
43
44
45
46
47
48
49
#include "main.h"
#include <stdarg.h>
/**
* _printf - takes the format string and replaces the supported
* directives by its equivalent argument
* @format: the string to format
* Return: the number characters printed to the screen
*/
int _printf(const char *format, ...)
{
int i, count = 0;
int (*func)(va_list *ap);
char c;
va_list arg_list;
va_list *va_ptr = &arg_list;
if (format == 0)
return (-1);
if (*format == 0)
return (0);
va_start(arg_list, format);
for (i = 0; i < _strlen((char *)format); i++)
{
if (format[i] != '%')
{
write(1, format + i, 1);
count++;
}
else
{
if (!spy_cmp(format[i + 1]))
{
continue;
}
c = format[i + 1];
func = get_format(c);
if (func == NULL)
printf("epic faliure :(");
else
count += func(va_ptr);
count++;
i++;
}
}
va_end(arg_list);
return (count);
}