-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
60 lines (56 loc) · 1.85 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
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-be <adiaz-be@student.42malaga.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/13 15:37:56 by adiaz-be #+# #+# */
/* Updated: 2022/10/13 15:40:08 by adiaz-be ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_format(va_list va, char *str, size_t *counter)
{
if (*str == 'c')
ft_putchar_pf(va_arg(va, int), counter);
else if (*str == 's')
ft_putstr_pf(va_arg(va, char *), counter);
else if (*str == 'p')
ft_putptr_pf(va_arg(va, void *), counter);
else if (*str == 'i' || *str == 'd')
ft_putnbr_pf(va_arg(va, int), counter);
else if (*str == 'u')
ft_putuint_pf(va_arg(va, unsigned int), counter);
else if (*str == 'x' || *str == 'X')
{
if (*str == 'x')
ft_puthex_pf(va_arg(va, unsigned int), counter, HEX_LOW_BASE);
else
ft_puthex_pf(va_arg(va, unsigned int), counter, HEX_UPP_BASE);
}
else if (*str == '%')
ft_putchar_pf(*str, counter);
}
int ft_printf(char const *str, ...)
{
va_list va;
size_t counter;
if (!str)
return (0);
counter = 0;
va_start(va, str);
while (*str)
{
if (*str == '%')
{
str++;
ft_format(va, (char *)str, &counter);
}
else
ft_putchar_pf(*str, &counter);
str++;
}
va_end(va);
return (counter);
}