-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_printf.c
More file actions
48 lines (47 loc) · 965 Bytes
/
_printf.c
File metadata and controls
48 lines (47 loc) · 965 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
45
46
47
48
#include <stdio.h>
#include "holberton.h"
#include <stdarg.h>
/**
* _printf - funtion to print according to format c, s, i, f, d
* @format: input format to print
* Return: integer to check what is
*/
int _printf(const char *format, ...)
{
va_list valist;
int b = 0, c = 0, d = 0, cuenf = 0, len = 0, e = 0;
formatico ops[] = {
{"c", printch}, {"s", prints}, {"i", printdi},
{"d", printdi}, {"%", printper}, {"b", printbi},
{"r", printrev}, {"R", printrot}
};
va_start(valist, format);
if (format == NULL)
return (-1);
while (format != NULL && format[b] != 0)
{
c = 0;
if (format[b] == '%')
{
for (d = 0; d < 8; d++)
{
if (format[b + 1] == 0)
return (-1);
if (format[b + 1] == *(ops[d].forma))
{
cuenf = cuenf + ops[d].f(valist);
c = 2;
e = e + 2;
b = b + 1;
break;
}
}
}
if (c == 0)
_putchar(format[b]);
b = b + 1;
}
len = b + cuenf - e;
va_end(valist);
return (len);
}