-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
47 lines (44 loc) · 905 Bytes
/
Copy path_printf.c
File metadata and controls
47 lines (44 loc) · 905 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
#include "main.h"
/**
* _printf - display text to stdout
* @format: string/text format
*
* Return: number of character successful displayed
*/
int _printf(const char *format, ...)
{
spec specs[] = {
{'c', print_char}, {'s', print_string},
{'%', print_percent}, {'d', print_integer},
{'i', print_integer}, {' ', print_space},
{'\0', print_space}, {'u', print_unsigned},
{'x', print_hex}, {'X', print_HEX},
{'o', print_unsigned_octal}, {'b', print_binary},
{'S', print_nonprintable},
};
int i, size, count = 0;
va_list ap;
va_start(ap, format);
size = sizeof(specs) / sizeof(specs[0]);
while (*format)
{
if (*format != '%')
{
count += _putchar(*format);
format++;
continue;
}
format++;
for (i = 0; i < size; i++)
{
if (*format == specs[i].specifier)
{
specs[i].func(ap, &count);
break;
}
}
format++;
}
va_end(ap);
return (count);
}