-
Notifications
You must be signed in to change notification settings - Fork 3
/
switch.c
53 lines (51 loc) · 1.08 KB
/
switch.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
#include "main.h"
/**
* selector - selects the appropriate specifiers
* @args: number of arguements
* @printed: the printed characters
* @format: the format specifier
* Return: printed charcaters
*/
int selector(const char *format, va_list args, int printed)
{
switch (*format)
{
case 'd':
case 'i':
printed = printf_integer(args, printed);
break;
case 'c':
_putchar(va_arg(args, int));
printed++;
break;
case 's':
printed = printf_string(args, printed);
break;
case '%':
_putchar('%');
printed++;
break;
case 'b':
printed = printf_binary(va_arg(args, unsigned int), printed);
break;
case 'x':
case 'X':
printed = _x(va_arg(args, unsigned int), printed, (*format == 'X') ? 1 : 0);
break;
case 'o':
printed = printf_octal(va_arg(args, unsigned int), printed);
break;
case 'u':
printed = printf_unsigned(va_arg(args, unsigned int), printed);
break;
case 'r':
printed = printf_reverse(args, printed);
break;
case 'p':
printed = printf_pointer(args, printed);
break;
default:
break;
}
return (printed);
}