-
Notifications
You must be signed in to change notification settings - Fork 0
/
_printf.c
113 lines (94 loc) · 1.98 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "main.h"
int _printf(const char *format, ...);
int print_character(va_list list);
int print_string(va_list list);
int print_percent(va_list list);
int print_integer(va_list list);
/**
* _printf - program startup
* @format: char being evaluated
(*
* Description: produces output according to a format)?
* Return: printed_values
*/
int _printf(const char *format, ...)
{
int printed_values;
print_t f_list[] = {
{"c", print_character},
{"s", print_string},
{"%", print_percent},
{"d", print_integer},
{"i", print_integer},
{NULL, NULL}
};
va_list arg_list;
if (format == NULL)
{
return (-1);
}
va_start(arg_list, format);
printed_values = string_format(format, f_list, arg_list);
va_end(arg_list);
return (printed_values);
}
/**
* print_character - program startup
* @list: variable argument being evaluated
(*
* Description: character output)?
* Return: return (1) is the required function signature
*/
int print_character(va_list list)
{
_not_putchar(va_arg(list, int));
return (1);
}
/**
* print_string - program startup
* @list: variable argument being evaluated
(*
* Description: string output)?
* Return: x
*/
int print_string(va_list list)
{
int x;
char *string;
string = va_arg(list, char *);
if (string == NULL)
{
string = "(null)";
}
for (x = 0; string[x] != '\0'; x++)
{
_not_putchar(string[x]);
}
return (x);
}
/**
* print_percent - program startup
* @list: variable argument being evaluated
(*
* Description: percent output
* https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Variable-Attributes.html)?
* Return: return (1) is the required function signature
*/
int print_percent(__attribute__((unused))va_list list)
{
_not_putchar('%');
return (1);
}
/**
* print_integer - program startup
* @list: variable argument being evaluated
(*
* Description: integer output)?
* Return: return (1) is the required function signature
*/
int print_integer(va_list list)
{
int number;
number = number_format(list);
return (number);
}