-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
51 lines (50 loc) · 830 Bytes
/
Copy path_printf.c
File metadata and controls
51 lines (50 loc) · 830 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 <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include "main.h"
/**
* _printf - all logic for the printf project.
* @format: string specifier formats.
*
* Return: Gives The length(char_num++).
*/
int _printf(const char *format, ...)
{
va_list ap;
unsigned int i = 0, char_num = 0;
if (!format)
return (-1);
va_start(ap, format);
for (i = 0; format[i] != '\0'; i++)
{
if (format[i] == '%')
{
if (format[i + 1] == '\0')
return (-1);
else if (format[i + 1] == '%')
{
_putchar('%');
char_num++;
i++;
}
else if (func(format[i + 1]) != NULL)
{
char_num += (func(format[i + 1]))(ap);
i++;
}
else
{
_putchar(format[i]);
char_num++;
}
}
else
{
_putchar(format[i]);
char_num++;
}
}
return (char_num);
va_end(ap);
}