-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_helper.c
79 lines (70 loc) · 1.92 KB
/
ft_print_helper.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
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akenji-a <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 17:41:41 by akenji-a #+# #+# */
/* Updated: 2022/05/16 13:04:32 by akenji-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_c(int c)
{
ft_putchar_fd(c, 1);
return (1);
}
int ft_print_s(char *str)
{
int len;
if (str == NULL)
{
ft_putstr_fd("(null)", 1);
return (6);
}
len = 0;
len = ft_strlen(str);
ft_putstr_fd(str, 1);
return (len);
}
int ft_print_id(int nbr)
{
char *nbr_int;
int len;
len = 0;
nbr_int = ft_itoa(nbr);
len = ft_strlen(nbr_int);
ft_putstr_fd(nbr_int, 1);
free(nbr_int);
return (len);
}
int ft_print_perc(void)
{
write(1, "%", 1);
return (1);
}
int ft_print_pxu(unsigned long long int nbr, const char *str)
{
char *nbr_pxu;
int len;
len = 0;
if (*str == 'p')
{
if (nbr == 0)
return (write(1, "(nil)", 5));
ft_putstr_fd("0x", 1);
nbr_pxu = ft_uuitoa(nbr, HEX_LOWER);
len = 2;
}
else if (*str == 'x')
nbr_pxu = ft_uuitoa((unsigned int) nbr, HEX_LOWER);
else if (*str == 'X')
nbr_pxu = ft_uuitoa((unsigned int) nbr, HEX_UPPER);
else if (*str == 'u')
nbr_pxu = ft_uuitoa((unsigned int) nbr, DECIMAL);
len = len + ft_strlen(nbr_pxu);
ft_putstr_fd(nbr_pxu, 1);
free(nbr_pxu);
return (len);
}