-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
51 lines (50 loc) · 1.02 KB
/
Copy path_printf.c
File metadata and controls
51 lines (50 loc) · 1.02 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
50
51
#include "main.h"
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
/**
* _printf - Custom implementation of the printf function.
* @format: The format string containing conversion specifiers.
*
* Return: The total number of characters printed (excluding null byte).
*/
int _printf(const char *format, ...)
{
int i = 0, count = 0, format_index;
print_specifiers arrayspecifiers[] = {
{'c', ctype}, {'%', mtype}, {'s', stype}, {'d', dtype},
{'i', itype}, {'b', btype}, {'\0', NULL}};
va_list args;
va_start(args, format);
if (format == NULL)
return (-1);
while (format[i] != '\0')
{
if (format[i] == '%')
{
i++;
if (format[i] == '\0')
{
va_end(args);
return (-1);
}
format_index = find_format_type(format[i], arrayspecifiers);
if (format_index >= 0)
count += arrayspecifiers[format_index].func(args);
else
{
_putchar('%');
_putchar(format[i]);
count += 2;
}
}
else
{
_putchar(format[i]);
count++;
}
i++;
}
va_end(args);
return (count);
}