-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
42 lines (39 loc) · 765 Bytes
/
printf.c
File metadata and controls
42 lines (39 loc) · 765 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
#include <dispatcher.h>
#include <format_specifier.h>
#include <parser.h>
#include <printf.h>
#include <stdarg.h>
#include <utils.h>
/**
* _printf - works just like the standard library printf
* @format: format specifier
* Return: number of bytes written to standard output
*/
int _printf(const char *format, ...)
{
int len = 0, bufsize = 0;
char buf[LENGTH];
va_list args;
struct FormatSpecifier fs;
va_start(args, format);
while (*format)
{
if (*format == '%')
{
format++;
parse_format_specifier(&format, &fs);
len += dispatch(&fs, &args, buf, &bufsize);
}
else
{
if (bufsize == LENGTH)
flush(buf, &bufsize);
buf[bufsize++] = *format;
format++;
len++;
}
}
flush(buf, &bufsize);
va_end(args);
return (len);
}