-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
68 lines (63 loc) · 1.86 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
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 19:04:09 by zwalad #+# #+# */
/* Updated: 2021/11/30 17:06:29 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_cdxu(char c, va_list args)
{
int size;
size = 0;
if (c == 'c')
size = ft_putchar(va_arg(args, int));
else if (c == '%')
size = ft_putchar(c);
else if (c == 'd' || c == 'i')
size = ft_putnbr(va_arg(args, int));
else if (c == 's')
size = ft_putstr(va_arg(args, char *));
else if (c == 'u')
size = ft_putuns(va_arg(args, unsigned int));
else if (c == 'x')
size = ft_hexa(va_arg(args, unsigned int), "0123456789abcdef");
else if (c == 'X')
size = ft_hexa(va_arg(args, unsigned int), "0123456789ABCDEF");
else if (c == 'p')
{
size = ft_putstr("0x");
size += ft_pupo(va_arg(args, unsigned long long), "0123456789abcdef");
}
return (size);
}
int ft_printf(const char *str, ...)
{
va_list args;
int size;
int i;
size = 0;
i = 0;
va_start(args, str);
while (str[i])
{
if (str[i] == '%')
{
i++;
size += ft_cdxu(str[i], args);
i++;
}
else
{
ft_putchar(str[i]);
i++;
size++;
}
}
va_end(args);
return (size);
}