-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprintf.c
More file actions
51 lines (48 loc) · 896 Bytes
/
printf.c
File metadata and controls
51 lines (48 loc) · 896 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 "main.h"
#include <stdarg.h>
#include <stddef.h>
/**
* _printf- prints anything in C!
*@format: format of the things to be printed
* Return: number of characters printed.
*/
int _printf(const char *format, ...)
{
int i, k;
va_list pams;
int (*func)(va_list);
if (format == NULL || (*(format) == '%' && *(format + 1) == '\0'))
return (-1);
va_start(pams, format);
i = 0;
k = 0;
while (format[i] != '\0')
{
if (format[i] == '%' && format[i + 1] != '\0')
{ func = sel_func(format[i + 1]);
if (func != NULL)
{ k += func(pams);
i += 2;
continue;
}
else
{
if (format[i + 1] == '%')
{ k += _putchar2(format[i + 1]);
i += 2;
continue;
}
else
{ k += _putchar2(format[i]);
k += _putchar2(format[i + 1]);
i += 2;
continue;
}
}
}
k += _putchar2(format[i]);
i++;
}
va_end(pams);
return (k);
}