-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
53 lines (45 loc) · 1.06 KB
/
_printf.c
File metadata and controls
53 lines (45 loc) · 1.06 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"
#include <stddef.h>
#include <stdio.h>
#include <stdalign.h>
/**
* _printf - custom function that formats and prints to std out
* @format: a directive that formats a string
* Return: the characters printed
*/
int _printf(const char *format, ...)
{
va_list list_of_args;
int index, buffer_index = 0;
double buffer_size_sum = 0;
char *temp;
char buff[BUFSIZE];
char *(*get_specifier)(va_list) = NULL;
if (format == NULL)
return (-1);
va_start(list_of_args, format);
for (index = 0; index < BUFSIZE; index++)
buff[index] = 0;
for (index = 0; format && format[index]; index++)
{
if (format[index] == '%')
{
index++;
get_specifier = get_specifier_funct(format[index]);
temp = (get_specifier) ? get_specifier
(list_of_args) : format_absent(format[index]);
if (temp)
buffer_index = assign_char(temp, _strlen(temp),
buff, buffer_index, &buffer_size_sum);
}
else
{
temp = conv_to_str(format[index]);
buffer_index = assign_char(temp, 1, buff,
buffer_index, &buffer_size_sum);
}
}
_puts(buff, buffer_index);
va_end(list_of_args);
return (buffer_size_sum + buffer_index);
}