-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_print.c
39 lines (36 loc) · 976 Bytes
/
get_print.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
#include "main.h"
/**
* get_print - selects the right printing function
* depending on the conversion specifier passed to _printf
* @s: character that holds the conversion specifier
* Description: the function loops through the structs array
* func_arr[] to find a match between the specifier passed to _printf
* and the first element of the struct, and then the approriate
* printing function
* Return: a pointer to the matching printing function
*/
int (*get_print(char s))(va_list, flags_t *)
{
ph func_arr[] = {
{'i', print_int},
{'s', print_string},
{'c', print_char},
{'d', print_int},
{'u', print_unsigned},
{'x', print_hex},
{'X', print_hex_big},
{'b', print_binary},
{'o', print_octal},
{'R', print_rot13},
{'r', print_rev},
{'S', print_bigS},
{'p', print_address},
{'%', print_percent}
};
int flags = 14;
register int i;
for (i = 0; i < flags; i++)
if (func_arr[i].c == s)
return (func_arr[i].f);
return (NULL);
}