-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
63 lines (58 loc) · 1.77 KB
/
ft_printf.c
File metadata and controls
63 lines (58 loc) · 1.77 KB
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
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: Cerdelen < cerdelen@student.42wolfsburg.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/04 20:19:13 by Cerdelen #+# #+# */
/* Updated: 2021/12/04 20:19:13 by Cerdelen ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int distributor(char c, va_list *args)
{
int count;
count = 0;
if (c == 'c')
count = case_c(args);
else if (c == 's')
count = case_s(args);
else if (c == '%')
count = case_pro();
else if (c == 'd' || c == 'i')
count = case_iord(args);
else if (c == 'u')
count = case_u(args);
else if (c == 'p')
count = case_p(args);
else if (c == 'x')
count = case_x(args);
else if (c == 'X')
count = case_xup(args);
return (count);
}
int ft_printf(const char *format, ...)
{
va_list args;
int count;
int ind;
count = 0;
ind = 0;
va_start(args, format);
while (format[ind])
{
if (format[ind] == '%')
count += distributor(format[ind + 1], &args);
if (format[ind] == '%')
ind += 2;
else
{
ft_printchar_fd(format[ind], 1);
count++;
ind++;
}
}
va_end(args);
return (count);
}