-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
58 lines (53 loc) · 1.7 KB
/
ft_printf.c
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
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yichoi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/13 15:29:11 by yichoi #+# #+# */
/* Updated: 2021/12/21 15:40:01 by yichoi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static char *to_find(FUNC_TYPE *operations, const char *format, va_list ap, ssize_t *count)
{
int i;
int n;
int check;
const char *option;
i = 0;
option = "cspdiuxX%";
n = sizeof(operations) / sizeof(char);
while (i < n && *format)
{
if (option[i] == *format)
{
*count = *count + (*(operations[i]))(ap);
break ;
}
i++;
}
return ((char *)format);
}
int ft_printf(const char *format_string, ...)
{
va_list ap;
ssize_t count;
FUNC_TYPE operations[9];
va_start(ap, format_string);
ft_format_specifier(operations);
count = 0;
while (*format_string)
{
if (*format_string != '%' && ++count)
write(1, format_string++, 1);
else
{
format_string = (const char *)to_find(operations, ++format_string, ap, &count);
format_string++;
}
}
va_end(ap);
return (count);
}