forked from Shadi-Shwiyat/holbertonschool-printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
43 lines (41 loc) · 795 Bytes
/
_printf.c
File metadata and controls
43 lines (41 loc) · 795 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
#include "main.h"
/**
* _printf - a typical printf
* @format: is a character string
* Return: the number of characters printed
*/
int _printf(const char *format, ...)
{
int i = 0, len = 0, ret = 0;
va_list arg;
if (format == NULL || (strlen(format) == 1 && format[0] == '%'))
{
return (-1);
}
va_start(arg, format);
while (format && format[i])
{
if (format[i] != '%')
{
putchar(format[i]);
len++;
}
if (format[i] == '%' && format[i + 1] != 'K' && format[i + 1] != '!')
{
ret = get_func(*(format + (i + 1)), arg);
if (ret != 0)
len += ret;
i += 2;
continue;
}
else if ((format[i] == '%' && format[i + 1] == 'K') ||
(format[i] == '%' && format[i + 1] == '!'))
{
putchar(format[i]);
len++;
}
i++;
}
va_end(arg);
return (len);
}