-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_print.c
39 lines (36 loc) · 977 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 appropriate
* printing function
* Return: a pointer to the matching printing function
*/
int (*get_print(char s))(va_list, mods *)
{
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},
{NUL, NULL}
};
register short i;
for (i = 0; func_arr[i].c; i++)
if (func_arr[i].c == s)
return (func_arr[i].f);
return (NULL);
}