-
Notifications
You must be signed in to change notification settings - Fork 0
/
printf.c
52 lines (49 loc) · 1.06 KB
/
printf.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
52
#include "main.h"
/**
* _printf - prints a formatted string
* @format: the format for printing
*
* Return: number of characters printed
*/
int _printf(const char *format, ...)
{ va_list args;
int i, count;
i = 0;
count = 0;
va_start(args, format);
while (format[i])
{
if (format[i] == '%')
{ i++;
while (format[i] == ' ')
i++;
if (is_in(format[i]))
{
if (format[i] == 'c')
count += write_character(va_arg(args, int));
else if (format[i] == 's')
count += write_string(va_arg(args, char *));
else if (format[i] == 'd' || format[i] == 'i')
count += print_number(va_arg(args, int));
else if (format[i] == 'b')
count += print_binary(va_arg(args, int));
else if (format[i] == 'R' || format[i] == 'r')
count += print_reverse(va_arg(args, char *));
else if (format[i] == '%')
count += write_character('%');
}
else
{
count += write_character(format[i - 1]);
count += write_character(format[i]);
}
i++;
}
else
{
count += write_character(format[i]);
i++;
}
}
return (count);
}