-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.c
More file actions
45 lines (43 loc) · 742 Bytes
/
printer.c
File metadata and controls
45 lines (43 loc) · 742 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
#include "main.h"
#include <stdarg.h>
#include <unistd.h>
/**
* _printf - clone printf in C
* @format: character string to print
* Return: number of characters printed
*/
int _printf(const char *format, ...)
{
int i = 0, count = 0, ret;
va_list args;
va_start(args, format);
if (!format)
return (-1);
while (format[i])
{
if (format[i] != '%')
count += _putchar(format[i]);
else
{
++i;
if (!format[i])
return (-1);
ret = choice(args, format[i]);
if (ret != (-7))
count += ret;
else
if (format[i] == '%')
count += _putchar(format[i]);
else
{
count += _putchar('%');
count += _putchar(format[i]);
}
i++;
continue;
}
++i;
}
va_end(args);
return (count);
}