-
Notifications
You must be signed in to change notification settings - Fork 0
/
getprintfmt.c
83 lines (78 loc) · 1.51 KB
/
getprintfmt.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "main.h"
/**
* print_fmt - a function that calls other functions
* @c: the character
* @list: aregument list
* @flag: handles the flags
* Return: 0
*/
int print_fmt(char c, va_list list, char flag)
{
int count = 0;
switch (c)
{
case 'c':
count += print_char((char)va_arg(list, int));
break;
case 's':
count += print_str(va_arg(list, char*));
break;
case ('S'):
count += print_S(va_arg(list, char*));
break;
case ('d'):
count += print_int((long)va_arg(list, int), flag);
break;
case ('i'):
count += print_int((long)va_arg(list, int), flag);
break;
case ('b'):
count += print_base((long)va_arg(list, int), 2, flag);
break;
case ('o'):
count += print_base((long)va_arg(list, int), 8, flag);
break;
case ('x'):
count += print_hex((long)va_arg(list, int), 'x', flag);
break;
default:
count += print_fmt2(c, list, flag);
break;
}
return (count);
}
/**
* print_fmt2 - Workd same as print_fmt
* @c: Character
* @list: argument list
* @flag: Handles the flag
* Return: count
*/
int print_fmt2(char c, va_list list, char flag)
{
int count = 0;
switch (c)
{
case ('X'):
count += print_hex((long)va_arg(list, int), 'X', flag);
break;
case ('p'):
count += print_ptr(va_arg(list, void*), 1);
break;
case ('u'):
count += print_u(va_arg(list, int), 10);
break;
case ('r'):
count += print_r(va_arg(list, char*));
break;
case ('R'):
count += print_R(va_arg(list, char*));
break;
default:
if (c != '%')
count += print_char('%');
count += print_char(c);
break;
}
return (count);
}