-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
57 lines (53 loc) · 1.77 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/24 11:11:21 by amacarul #+# #+# */
/* Updated: 2024/09/26 18:23:46 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void select_format(va_list arg, char *str, size_t *count)
{
if (*str == 'c')
ft_pfchar(va_arg(arg, int), count);
else if (*str == 's')
ft_pfstr(va_arg(arg, char *), count);
else if (*str == 'p')
ft_pfptrhex(va_arg(arg, void *), count);
else if (*str == 'd' || *str == 'i')
ft_pfnbr(va_arg(arg, int), count);
else if (*str == 'u')
ft_pfunsgn(va_arg(arg, unsigned int), count);
else if (*str == 'x')
ft_pfhex(va_arg(arg, unsigned int), 1, count);
else if (*str == 'X')
ft_pfhex(va_arg(arg, unsigned int), 2, count);
else if (*str == '%')
ft_pfchar('%', count);
}
int ft_printf(char const *str, ...)
{
va_list arg;
size_t count;
if (!str)
return (0);
va_start(arg, str);
count = 0;
while (*str)
{
if (*str == '%')
{
str ++;
select_format(arg, (char *) str, &count);
}
else
ft_pfchar(*str, &count);
str ++;
}
va_end(arg);
return (count);
}