-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintf_struct.c
42 lines (41 loc) · 906 Bytes
/
printf_struct.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
#include "holberton.h"
#include <stdio.h>
/**
* printf_struct - Indicates the function to follow according
* the structure
* @s: Is the string send from the function _printf
* @index: is the position after % symbol in the string
* Return: the data to the function to process
*/
int (*printf_struct(const char *s, int index))(va_list, int)
{
data_t ops[] = {
{"c", printfchar},
{"s", printfstring},
{"R", print_rot},
{"b", print_binary},
{"S", printf_string_new},
{"p", printf_pointer},
{"d", printfint},
{"i", printfint},
{"u", printf_unsig},
{"x", printf_hexa},
{"X", printf_mhexa},
{"o", printf_octal},
{NULL, NULL}
};
int i = 0;
if (s[index] == '+' || s[index] == ' ' || s[index] == '#' ||
s[index] == 'h' || s[index] == 'l')
{
i = 6;
index++;
}
while (ops[i].data)
{
if (ops[i].data[0] == s[index])
return (ops[i].func);
i++;
}
return (NULL);
}