forked from waffle52/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf.c
More file actions
51 lines (48 loc) · 991 Bytes
/
Copy pathprintf.c
File metadata and controls
51 lines (48 loc) · 991 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
#include "holberton.h"
/**
* _printf - function that prints different formats of data and
* returns the number of bytes sent to the output stream
* @format: Const char pointer that contains conversion specifiers
* Return: Int of total number of bytes printed
*/
int _printf(const char *format, ...)
{
int byte_sum = 0, i, sp;
va_list args;
va_start(args, format);
if (format == NULL || (format[0] == '%' && format[1] == '\0'))
{
va_end(args);
return (-1);
}
for (i = 0; format[i]; i++)
{
if (format[i] == '%')
{
sp = special_ch(format[i + 1]);
if (format[i + 1] == '%')
{
byte_sum += _putchar(format[i + 1]);
i++;
continue;
}
if (sp == 1)
{
byte_sum += get_format(format[i + 1])(args);
i++;
continue;
}
else if (sp == 0)
{
byte_sum += _putchar(format[i]);
byte_sum += _putchar(format[i + 1]);
i++;
continue;
}
}
else
byte_sum += _putchar(format[i]);
}
va_end(args);
return (byte_sum);
}