-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
49 lines (48 loc) · 823 Bytes
/
printf.c
File metadata and controls
49 lines (48 loc) · 823 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
#include "main.h"
/**
*_printf - prints a format string with arguments passed
*@format:a const char pointer
*Return:the length
*
*/
int _printf(const char *format, ...)
{
char *buffer;
char* (*action)(va_list, char *);
int i = 0, length;
va_list args;
buffer = initialisation(format);
va_start(args, format);
while (format[i] != '\0')
{
if (format[i] != '%')
{
buffer = _addchar(buffer, format[i]);
i++;
}
else
{
i++;
if (format[i] == '%')
{
buffer = _addchar(buffer, '%');
i++;
}
else
{
action = get_action_specifier(format[i]);
if (action == NULL)
{
buffer = _addchar(buffer, '%');
i++;
}
buffer = action(args, buffer);
i++;
}
}
}
_putstring(buffer);
length = _strlen(buffer);
free_vars(buffer, args);
return (length);
}