-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFunc_and_buffer_functions.c
64 lines (56 loc) · 1.1 KB
/
getFunc_and_buffer_functions.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "main.h"
/**
* get_func - returns needed function
* @i: identifier for function
* Return: Pointer to needed function
*/
char* (*get_func(char i))(va_list)
{
int k = 0;
print keys[] = {
{'c', print_c},
{'s', print_s},
{'d', print_d},
{'i', print_d},
{'b', itob},
{'x', itox},
{'X', itoX},
{'R', rot13},
{'r', rev_string},
{'o', itoo},
{'\0', NULL}
};
while (keys[k].id != '\0')
{
if (keys[k].id == i)
return (keys[k].func);
k++;
}
return (NULL);
}
/**
* create_buffer - creates buffer to hold string until it's ready for print
* Return: pointer to buffer created
*/
char *create_buffer(void)
{
char *buffer;
buffer = malloc(sizeof(char) * 1024);
if (buffer == NULL)
return (NULL);
return (buffer);
}
/**
* write_buffer - prints buffer, then frees it and frees va_list
* @buffer: buffer holding print-ables
* @len: length of print-able string
* @list: va_list
*/
void write_buffer(char *buffer, int len, va_list list)
{
char *buff;
buff = realloc(buffer, len); /* realloc to correct size */
write(1, buff, len); /* print */
free(buff);
va_end(list);
}