-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_prinft.c
59 lines (54 loc) · 1.7 KB
/
ft_prinft.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_prinft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: badriano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 20:49:22 by badriano #+# #+# */
/* Updated: 2024/05/22 21:03:36 by badriano ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_print_formats(va_list v, const char c)
{
int len;
len = 0;
if (c == 'c')
len += ft_printchar(va_arg(v, int));
else if (c == 's')
len += ft_printstr(va_arg(v, char *));
else if (c == 'p')
ft_print_point(va_arg(v, long long int), &len);
else if (c == 'd' || c == 'i')
len += ft_printnbr(va_arg(v, int));
else if (c == 'u')
ft_print_unsigned(va_arg(v, unsigned int), &len);
else if (c == 'x' || c == 'X')
ft_print_hex(va_arg(v, unsigned int), c, &len);
else if (c == '%')
len += ft_printchar('%');
return (len);
}
int ft_printf(const char *s, ...)
{
va_list v;
int i;
int len;
len = 0;
i = 0;
va_start(v, s);
while (s[i])
{
if (s[i] == '%')
{
len += ft_print_formats(v, s[i + 1]);
i++;
}
else
len += ft_printchar(s[i]);
i++;
}
va_end(v);
return (len);
}