-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
75 lines (68 loc) · 2.17 KB
/
ft_printf.c
File metadata and controls
75 lines (68 loc) · 2.17 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
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edforte <edforte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/03 13:20:51 by edforte #+# #+# */
/* Updated: 2024/02/06 17:03:40 by edforte ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_arguments(char type, va_list argp)
{
int i;
i = 0;
if (type == '%')
return (ft_putchar('%'));
else if (type == 'c')
return (ft_putchar(va_arg(argp, int)));
else if (type == 's')
return (ft_putstr(va_arg(argp, char *)));
else if (type == 'p')
return (ft_pointer(va_arg(argp, unsigned long), "0123456789abcdef"));
else if (type == 'd' || type == 'i')
return (ft_putnbr(va_arg(argp, int)));
else if (type == 'u')
return (ft_put_uns_nbr(va_arg(argp, unsigned int)));
else if (type == 'x')
return (ft_put_low_hex(va_arg(argp, unsigned int), "0123456789abcdef"));
else if (type == 'X')
return (ft_put_upp_hex(va_arg(argp, unsigned int), "0123456789ABCDEF"));
return (i);
}
int ft_printf(const char *format, ...)
{
va_list argp;
int i;
i = 0;
va_start(argp, format);
while (*format)
{
if (*format == '%')
{
format ++;
i += print_arguments(*format, argp);
}
else
i += ft_putchar(*format);
format ++;
}
va_end(argp);
return (i);
}
// int main(void)
// {
// int x;
// int y;
// int z;
// x = 420;
// y = printf("ciao come va %d\n", x);
// z = ft_printf("ciao come va %d\n", x);
// printf("ciao come va %d\n", x);
// ft_printf("ciao come va %d\n", x);
// printf("questa e'y %d\n", y);
// printf("questa e'z %d\n", z);
// return (0);
// }