-
Notifications
You must be signed in to change notification settings - Fork 0
/
_handlagrs.c
52 lines (47 loc) · 1006 Bytes
/
_handlagrs.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
#include "main.h"
/**
*_handlagrs - this function handl the cases after %.
*
*@format: the format from the _printf
*@i: counter of loop in _printf function
*@args: args list.
*@buffer: is the stirng to be handl
*Return: the lenght printed on success or -1 if null byte
*/
int _handlagrs(const char *format, int *i, va_list args, char *buffer)
{
int k = 0, lenused;
specifier speci[] = {
{'c', _putchar},
{'s', _strcase},
{'%', _prcntcase},
{'i', _print_integer},
{'d', _print_integer},
{'\0', NULL}
};
while (speci[k].c != '\0')
{
if (format[*i] == speci[k].c)
{
return (speci[k].func(args, buffer));
}
k++;
}
/*if (variabletype[k].c == '\0')*/
lenused = 0;
if (format[*i] != '\0')
{
lenused = lenused + write(MYSTDOUT_FILENO, "%%", 1);
if (format[*i - 1] == ' ')
{
lenused += write(MYSTDOUT_FILENO, " ", 1);
}
lenused += write(MYSTDOUT_FILENO, &format[*i], 1);
}
else
{
if (speci[k].c == '\0')
return (-1);
}
return (lenused);
}