-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
38 lines (36 loc) · 1023 Bytes
/
_printf.c
File metadata and controls
38 lines (36 loc) · 1023 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
#include "main.h"
/**
* _printf - function that produces output according to a format.
*
* Description: function that produces output according to a format.
*
* @format: String format
*
* Return: number of characters printed
*/
int _printf(const char *format, ...)
{
int format_position, number_of_characters_printed;
va_list all_parameters;
if (format == 0)
return (-1);
else if (format[0] == '%' && format[1] == '\0')
return (-1);
va_start(all_parameters, format);
format_position = number_of_characters_printed = 0;
while (format[format_position] != '\0')
{
if (format[format_position] == '%' && format[format_position + 1] != '\0')
number_of_characters_printed += process_flag(format[format_position + 1],
all_parameters);
if (!is_flag(format[format_position], format[format_position + 1]))
{
number_of_characters_printed += _putchar(format[format_position]);
format_position++;
}
else
format_position += 2;
}
va_end(all_parameters);
return (number_of_characters_printed);
}