-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
49 lines (41 loc) · 1.28 KB
/
Copy path_printf.c
File metadata and controls
49 lines (41 loc) · 1.28 KB
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
#include "main.h"
/**
* _printf - A custom implementation of the printf function.
*
* @format: The format string that specifies how subsequent arguments are
* converted for output.
*
* This function takes a format string and a variable number of arguments,
* initializes an arg_data_t struct and an array of specifier_t structs, and
* processes the format string. If the format string is NULL, it returns -1.
* It uses the process_format_string function to process the format string and
* update the count of printed characters in the arg_data_t struct.If the count
* is -1 after processing the format string, it returns -1. Otherwise, it ends
* the va_list in the arg_data_t struct and returns the count of printed
* characters.
*
* Return: The total count of printed characters if the format string is
* processed successfully, -1 otherwise.
*/
int _printf(const char *format, ...)
{
arg_data_t data;
specifier_t *specifiers = init_specifiers();
flag_t *flags = init_flags();
va_start(data.args, format);
data.count = 0;
data.i = 0;
data.flags = 0;
if (format == NULL)
{
return (-1);
}
process_format_string(format, specifiers, flags, &data);
if (data.count == -1)
{
return (-1);
}
va_end(data.args);
flush_buffer(&data); /* flush the buffer */
return (data.count);
}