-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetfunc.c
More file actions
41 lines (33 loc) · 877 Bytes
/
getfunc.c
File metadata and controls
41 lines (33 loc) · 877 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
#include "holberton.h"
/**
* getfunc - function takes in a specifier in the form of a char
* and returns the associated function to print an argument of that type
*
* @s: type char, the specifier passed in
*
* Description: an array of structs is initialized with all possible specifiers
* and the associated functions that will print arguments of that type
*
* Return: integer value, the number of characters printed when the called
* function (via a function pointer) prints characters
*/
int (*getfunc(char s))(va_list)
{
int i = 0;
specdo arr[] = { {'c', _printchar},
{'s', _printstring},
{'d', _putint},
{'i', _putint},
{'%', _percent},
{'b', _printbinary},
{'r', _printrevstring},
{'R', _printrot13},
{'\0', NULL}};
while (arr[i].s != '\0')
{
if (s == arr[i].s)
return (arr[i].prntr);
i++;
}
return (_negativeone);
}