-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
48 lines (44 loc) · 838 Bytes
/
_printf.c
File metadata and controls
48 lines (44 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
#include "main.h"
/**
* _printf - Print like a printf
* @format: Args to the function
*
* Return: A format string to output
*/
int _printf(const char *format, ...)
{
int count = 0;
va_list args;
if (format == NULL)
return (-1);
va_start(args, format);
while (*format)
{
if (*format == '%')
{
while (*(format + 1) == ' ')
format++;
format++;
if (*format == '\0' || *format == ' ')
return (-1);
if (*format == 'c')
count += handle_c(args);
else if (*format == 's')
count += handle_s(args);
else if (*format == '%')
count += print_char('%');
else if (*format == 'd' || *format == 'i')
count += print_int(args);
else
{
format--;
count += print_char(*format);
}
}
else
count += print_char(*format);
format++;
}
va_end(args);
return (count);
}