-
Notifications
You must be signed in to change notification settings - Fork 0
/
_printf.c
57 lines (49 loc) · 848 Bytes
/
_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
53
54
55
56
57
#include "main.h"
/**
* _printf - process a string and variable number of arguments
* @format: the string to process
* @...: variable number of arguments
*
* Return: 0
*/
int _printf(const char *format, ...)
{
int counter = 0;
va_list args;
va_start(args, format);
while (*format != '\0')
{
if (*format == '%')
{
format++;
if (*format == 'c')
{
char s = va_arg(args, int);
counter += _putchar(s);
}
else if (*format == 's')
{
char *str = va_arg(args, char *);
counter += _print_string(str);
}
else if (*format == 'd' || *format == 'i')
{
int i = va_arg(args, int);
counter += _print_int(i);
}
else if (*format == '%')
{
_putchar('%');
counter++;
}
}
else
{
_putchar(*format);
counter++;
}
format++;
}
va_end(args);
return (counter);
}