-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_specifier.c
73 lines (65 loc) · 1.76 KB
/
p_specifier.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
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* x_specifier.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jinpark <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 21:53:43 by jinpark #+# #+# */
/* Updated: 2019/04/23 19:29:31 by jinpark ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int p_specifier(char *str, va_list *ap, t_store *a, int i)
{
void *p;
uint64_t ptr;
int j;
char *temp;
(void)i;
j = 0;
if (*str != '\0')
{
p = va_arg(*ap, void *);
ptr = *((uint64_t *)(&p));
temp = p_itoa_base(ptr, HEXA);
a->len = ft_strlen(temp);
j = res_handler(a);
a->wid = width_handler(a);
ft_putstr("0x");
if (p == 0)
ft_putchar('0');
else
ft_putstr(temp);
j += 2;
free(temp);
}
return (j);
}
int percent_sp(char *str, va_list *ap, t_store *a, int i)
{
(void)ap;
if (str[i + 1] == '-')
percent_minus_print(a);
else
percent_print(a);
return (res_handler(a));
}
void percent_print(t_store *a)
{
int i;
i = 0;
if (a->wid != 0)
while (++i < a->wid)
ft_putchar(' ');
ft_putchar('%');
}
void percent_minus_print(t_store *a)
{
int i;
i = 0;
ft_putchar('%');
if (a->wid != 0)
while (++i < a->wid)
ft_putchar(' ');
}