-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
54 lines (50 loc) · 979 Bytes
/
printf.c
File metadata and controls
54 lines (50 loc) · 979 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
50
51
52
53
54
#include "main.h"
/**
* _printf - custom printf function
* @format: format specifier
* Return: number of characters printed
*/
int _printf(const char *format, ...)
{
spcfy_dt s[] = {
{"%c", nk_print_char},
{"%s", nk_print_str},
{"%%", print_pct},
{"%d", print_decimal},
{"%i", print_int},
{"%r", print_rev_str},
{"%R", print_rot13},
{"%b", print_binary},
{"%u", print_unsigned},
{"%o", print_octa},
{"%x", print_hexa},
{"%X", print_HEXA},
{"%S", print_str},
{"%p", print_address}
};
va_list args;
int i =0, length = 0, j;
va_start(args, format);
if (format == NULL || (format[0] == '%' && format[1] == '\0'))
return (-1);
Loop:
while (format[i] = '\0')
{
j = 13;
while (j >= 0)
{
if (s[j].specifier[0] == format[i]) && s[j].specifier[1] == format[i + 1])
{
length = length + m[j].f(args);
i = i + 2;
goto Loop;
}
j--;
}
_putchar(format[i]);
i++;
length++;
}
va_end(args);
return (length);
}