-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testing_printf2
56 lines (49 loc) · 965 Bytes
/
Testing_printf2
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
52
53
54
55
56
#include "main.h"
/**
* _printf - produces output according to a format
* @format: format string that contains plain text and conversion
* specifications
*
* Return: number of characters written
*/
int _printf(const char *format, ...)
{
va_list args;
int count = 0;
int *count_ptr = &count;
va_start(args, format);
if (format == NULL)
return (-1);
printcs(format, count_ptr, args);
va_end(args);
return (count);
}
/**
* printcs - print format string, arguments and update return value
* @format: format string
* @count_ptr: pointer to count
* @args: args
*
* Return: void.
*/
void printcs(const char *format, int *count_ptr, va_list args)
{
int (*conversions[256])(va_list, int *);
int count = 0;
char c;
init_conversions(conversions);
while ((c = *format++))
{
if (c != '%')
{
_putchar(c);
count++;
}
else
{
c = *format++;
count += conversions[(unsigned char)c](args, &count);
}
}
*count_ptr = count;
}