-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
78 lines (70 loc) · 2.09 KB
/
ft_printf.c
File metadata and controls
78 lines (70 loc) · 2.09 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
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bhielsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/20 10:33:34 by bhielsch #+# #+# */
/* Updated: 2022/10/20 10:35:53 by bhielsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_print_percentage(char c);
static int ft_type(va_list args, const char type);
int ft_printf(const char *str, ...)
{
int i;
int len;
va_list args;
i = 0;
len = 0;
va_start(args, str);
while (str[i])
{
if (str[i] == '%')
{
i++;
len += ft_type(args, str[i]);
}
else
len += ft_print_c(str[i]);
i++;
}
va_end(args);
return (len);
}
int ft_type(va_list args, const char type)
{
int len;
len = 0;
if (type == 'c')
len += ft_print_c(va_arg(args, int));
else if (type == '%')
len += ft_print_percentage('%');
else if (type == 'x')
len += ft_print_hexlow(va_arg(args, unsigned int), 1);
else if (type == 'X')
len += ft_print_hexup(va_arg(args, unsigned int), 1);
else if (type == 'i' || type == 'd')
len += ft_print_int(va_arg(args, int), 1);
else if (type == 'p')
len += ft_print_p(va_arg(args, void *));
else if (type == 'u')
len += ft_print_u(va_arg(args, unsigned int));
else if (type == 's')
len += ft_print_str(va_arg(args, char *));
return (len);
}
int ft_print_percentage(char c)
{
write(1, &c, 1);
return (1);
}
// int main()
// {
// int nb = 4294967294;
// void *ptr = &nb;
// ft_printf("Mine:%p", ptr);
// printf("\nOG: %p", ptr);
// }