-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
64 lines (59 loc) · 1.84 KB
/
ft_printf.c
File metadata and controls
64 lines (59 loc) · 1.84 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
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acosta-a <acosta-a@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/30 03:08:03 by acosta-a #+# #+# */
/* Updated: 2022/05/19 14:03:31 by acosta-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int check_print(va_list arg, const char type)
{
int len;
len = 0;
if (type == 'c')
len = len + ft_printchar(va_arg(arg, int));
if (type == 'd' || type == 'i')
len = len + ft_putnbr_len(va_arg(arg, int), 1);
if (type == 'u')
len = len + ft_uputnbr_len(va_arg(arg, int), 1);
if (type == 's')
len = len + ft_putstr_fd(va_arg(arg, char *), 1);
if (type == '%')
len = len + ft_printpercent();
if (type == 'x')
len = len + ft_puthex_len(va_arg(arg, int), 1, 0);
if (type == 'X')
len = len + ft_puthex_len(va_arg(arg, int), 1, 1);
if (type == 'p')
len = len + ft_putptr(va_arg(arg, unsigned long long), 1, 0);
return (len);
}
int ft_printf(const char *type, ...)
{
va_list arg;
int i;
int len;
i = 0;
len = 0;
va_start(arg, type);
while (type[i] != '\0')
{
if (type[i] == '%')
{
i++;
len = len + check_print(arg, type[i]);
}
else
{
ft_printchar (type[i]);
len++;
}
i++;
}
va_end (arg);
return (len);
}