-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
53 lines (50 loc) · 838 Bytes
/
_printf.c
File metadata and controls
53 lines (50 loc) · 838 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
49
50
51
52
53
#include "holberton.h"
#include <stdarg.h>
/**
* _printf - produces output according to a format
* @format: string that gives the format
* Return: an integer
*/
int _printf(const char *format, ...)
{
int count = 0;
va_list args;
if (!format)
return (-1);
va_start(args, format);
while (*format != '\0')
{
if (*format != '%')
{
_putchar(*format);
count++;
format++;
continue;
}
format++;
if (*format == '\0')
{
return (-1);
}
if (*format != 'c' && *format != 's' && *format != 'd'
&& *format != 'i' && *format != '%')
{
_putchar('%');
_putchar(*format);
count += 2;
format++;
continue;
}
if (*format == '%')
{
_putchar(*format);
count++;
format++;
continue;
}
count += (*get_sel(*format))(args);
format++;
}
va_end(args);
return (count);
}