-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
52 lines (48 loc) · 1.63 KB
/
ft_printf.c
File metadata and controls
52 lines (48 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/10 19:25:00 by bguzel #+# #+# */
/* Updated: 2022/11/22 15:01:02 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void formatter(va_list s, char c, int *count)
{
if (c == 'd' || c == 'i')
print_int(va_arg(s, int), count);
else if (c == 'c')
print_char(va_arg(s, int), count);
else if (c == 's')
print_string(va_arg(s, char *), count);
else if (c == 'u')
print_unsigned(va_arg(s, unsigned int), count);
else if (c == 'p')
print_ptr(va_arg(s, unsigned long), count);
else if (c == 'X' || c == 'x')
print_hex(va_arg(s, unsigned int), c, count);
else if (c == '%')
print_char('%', count);
}
int ft_printf(const char *s, ...)
{
int i;
int count;
va_list lst;
va_start(lst, s);
count = 0;
i = 0;
while (s[i])
{
if (s[i] == '%')
formatter(lst, s[++i], &count);
else
print_char(s[i], &count);
i++;
}
va_end(lst);
return (count);
}