-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
71 lines (64 loc) · 1.98 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
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: damartin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 13:36:39 by damartin #+# #+# */
/* Updated: 2022/05/04 13:37:04 by damartin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int format(va_list args, char form)
{
int size;
size = 0;
if (form == 'c')
size += printchar(va_arg(args, int));
else if (form == 's')
size += printstr(va_arg(args, char *));
else if (form == 'p')
size += print_ptr(va_arg(args, unsigned long long));
else if (form == 'd')
size += printnbr(va_arg(args, int));
else if (form == 'i')
size += printnbr(va_arg(args, int));
else if (form == 'u')
size += print_unsigned(va_arg(args, unsigned int));
else if (form == 'x')
size += print_hexa(va_arg(args, unsigned int), form);
else if (form == 'X')
size += print_hexa(va_arg(args, unsigned int), form);
else if (form == '%')
size += printchar('%');
return (size);
}
int ft_printf(const char *str, ...)
{
int i;
int total_size;
va_list arg;
i = 0;
total_size = 0;
va_start(arg, str);
while (str[i])
{
if (str[i] == '%')
total_size += format(arg, str[i++]);
else
total_size += printchar(str[i]);
i++;
}
va_end(arg);
return (total_size);
}
int main(void)
{
char a, b, c;
a = 'a';
b = 'v';
c = 'q';
ft_printf("Testing chars: %c, %c, %c\n", a, b, c);
return (0);
}