-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.c
More file actions
53 lines (51 loc) · 985 Bytes
/
switch.c
File metadata and controls
53 lines (51 loc) · 985 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 "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 p)
{
switch (*format)
{
case 'd':
case 'i':
p = printf_int(args, p);
break;
case 'c':
_putchar(va_arg(args, int));
p++;
break;
case 's':
p = printf_str(args, p);
break;
case '%':
_putchar('%');
p++;
break;
case 'b':
p = printf_binary(va_arg(args, unsigned int), p);
break;
case 'x':
case 'X':
p = printf_hex(va_arg(args, unsigned int), p, (*format == 'X') ? 1 : 0);
break;
case 'o':
p = printf_octal(va_arg(args, unsigned int), p);
break;
case 'u':
p = printf_unsigned(va_arg(args, unsigned int), p);
break;
case 'r':
p = printf_reverse(args, p);
break;
case 'p':
p = printf_ptr(args, p);
break;
default:
break;
}
return (p);
}