-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
58 lines (51 loc) · 916 Bytes
/
_printf.c
File metadata and controls
58 lines (51 loc) · 916 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include <stddef.h>
/**
* _printf - recreates the printf function
* @format: string with format specifier
* Return: number of characters printed
*/
int _printf(const char *format, ...)
{
if (format != NULL)
{
int count = 0, i;
int (*m)(va_list);
va_list args;
va_start(args, format);
i = 0;
if (format[0] == '%' && format[1] == '\0')
return (-1);
while (format != NULL && format[i] != '\0')
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{
count += _putchar(format[i]);
i += 2;
}
else
{
m = get_func(format[i + 1]);
if (m)
count += m(args);
else
count = _putchar(format[i]) + _putchar(format[i + 1]);
i += 2;
}
}
else
{
count += _putchar(format[i]);
i++;
}
}
va_end(args);
return (count);
}
return (-1);
}