-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_print_func.c
58 lines (57 loc) · 1.55 KB
/
get_print_func.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
50
51
52
53
54
55
56
57
58
#include "main.h"
/**
* get_print_func - selects the correct function to perform the operation.
* @s: argument indentifier
* @index: index for argument indentifier
* Return: pointer to a function.
*/
int (*get_print_func(const char *s, int index))(va_list, char *, unsigned int)
{
print_t pr[] = {
{"c", print_chr}, {"s", print_str},
{"i", print_int}, {"d", print_int},
{"b", print_bnr}, {"u", print_unt},
{"o", print_oct}, {"x", print_hex},
{"X", print_upx}, {"S", print_usr},
{"p", print_add}, {"li", prinlint},
{"ld", prinlint}, {"lu", prinlunt},
{"lo", prinloct}, {"lx", prinlhex},
{"lX", prinlupx}, {"hi", prinhint},
{"hd", prinhint}, {"hu", prinhunt},
{"ho", prinhoct}, {"hx", prinhhex},
{"hX", prinhupx}, {"#o", prinnoct},
{"#x", prinnhex}, {"#X", prinnupx},
{"#i", print_int}, {"#d", print_int},
{"#u", print_unt}, {"+i", prinpint},
{"+d", prinpint}, {"+u", print_unt},
{"+o", print_oct}, {"+x", print_hex},
{"+X", print_upx}, {" i", prinsint},
{" d", prinsint}, {" u", print_unt},
{" o", print_oct}, {" x", print_hex},
{" X", print_upx}, {"R", print_rot},
{"r", print_rev}, {"%", print_prg},
{"l", print_prg}, {"h", print_prg},
{" +i", prinpint}, {" +d", prinpint},
{"+ i", prinpint}, {"+ d", prinpint},
{" %", print_prg}, {NULL, NULL},
};
int i = 0, j = 0, first_index;
first_index = index;
while (pr[i].type_arg)
{
if (s[index] == pr[i].type_arg[j])
{
if (pr[i].type_arg[j + 1] != '\0')
index++, j++;
else
break;
}
else
{
j = 0;
i++;
index = first_index;
}
}
return (pr[i].f);
}