-
Notifications
You must be signed in to change notification settings - Fork 3
/
ev_print_func.c
51 lines (49 loc) · 1.48 KB
/
ev_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
#include "main.h"
/**
* ev_print_func - returns the amount of identifiers.
* @s: argument indentifier
* @index: index of argument identifier.
* Return: amount of identifiers.
*/
int ev_print_func(const char *s, int index)
{
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 (j);
}