-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
51 lines (49 loc) · 1.06 KB
/
parser.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
#include "main.h"
/**
* parser - Receives the main string and all the necessary parameters to
* print a formated string.
* @format: A string containing all the desired characters.
* @f_list: A list of all the posible functions.
* @arg_list: A list containing all the argumentents passed to the program.
* Return: A total count of the characters printed.
*/
int parser(const char *format, _cvrt f_list[], va_list arg_list)
{
int i, j, r_val, p_chars;
p_chars = 0;
for (i = 0; format[i] != '\0'; i++)
{
if (format[i] == '%')
{
for (j = 0; f_list[j].symbol != NULL; j++)
{
if (format[i + 1] == f_list[j].symbol[0])
{
r_val = f_list[j].f(arg_list);
if (r_val == -1)
return (-1);
p_chars += r_val;
break;
}
}
if (f_list[j].symbol == NULL && format[i + 1] != ' ')
{
if (format[i + 1] != '\0')
{
_putchar(format[i]);
_putchar(format[i + 1]);
p_chars = p_chars + 2;
}
else
return (-1);
}
i = i + 1;
}
else
{
_putchar(format[i]);
p_chars++;
}
}
return (p_chars);
}