-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
44 lines (41 loc) · 704 Bytes
/
_printf.c
File metadata and controls
44 lines (41 loc) · 704 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
41
42
43
44
#include "main.h"
/**
* _printf - function that produces output according to a format.
* @format: pointer to format string
* Return: count of printed characters.
*/
int _printf(const char *format, ...)
{
int count;
int i;
int j;
va_list args;
my_type m[] = {{"%%", prt_percent}, {"%S", prt_string}, {"%c", prt_char}};
count = 0;
i = 0;
if (format == NULL)
return (0);
va_start(args, format);
while (format[i] != '\0')
{
if (format[i] != '%')
{
count++;
_putchar(format[i]);
}
else
{
for (j = 0 ; j < 3 ; j++)
{
if (m[j].id[1] == format[i + 1])
{
count += m[j].function(args);
}
}
i = i + 1;
}
i++;
}
va_end(args);
return (count);
}