-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
70 lines (65 loc) · 1.89 KB
/
ft_printf.c
File metadata and controls
70 lines (65 loc) · 1.89 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
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ilnassi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/09 14:30:18 by ilnassi #+# #+# */
/* Updated: 2025/01/16 15:04:54 by ilnassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_formats(va_list args, const char format)
{
if (format == 'c')
return (ft_putchar(va_arg(args, int)));
if (format == 's')
return (ft_putstr(va_arg(args, char *)));
if (format == 'p')
return (ft_print_ptr(va_arg(args, void *)));
if (format == 'd' || format == 'i')
return (ft_putnbr(va_arg(args, int)));
if (format == 'u')
return (ft_putnbr_unsigned(va_arg(args, unsigned int)));
if (format == 'x')
return (ft_print_hexa(va_arg(args, unsigned int), 0));
if (format == 'X')
return (ft_print_hexa(va_arg(args, unsigned int), 1));
if (format == '%')
return (ft_putpercent());
else
return (0);
}
int ft_printf(const char *form, ...)
{
va_list args;
int count;
count = 0;
va_start (args, form);
while (*form)
{
if (*form == '%')
{
form++;
count += ft_formats(args, *form);
}
else
{
count += ft_putchar(*form);
}
form++;
}
va_end(args);
return (count);
}
/*
int main()
{
int x;
int len;
x = 42;
len = ft_printf("%p", &x);
printf("\n%d\n", len);
}
*/