-
Notifications
You must be signed in to change notification settings - Fork 0
/
printers.c
104 lines (94 loc) · 2.3 KB
/
printers.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kalmheir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/30 18:33:34 by kalmheir #+# #+# */
/* Updated: 2022/05/31 09:20:19 by kalmheir ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
* Function: putstrip
* --------------------
* Prints a string to stdout with the option to ignore
* percentage signs
*
* parameters:
* str: string to be printed
* ignore_percent: boolean value whether or not to ignore %
*/
void putstrip(const char *str, char ignore_percent, size_t *count)
{
int i;
i = 0;
if (str == 0)
{
putstrip("(null)", 0, count);
return ;
}
while (str[i])
{
if (str[i] == '%' && ignore_percent)
{
i++;
continue ;
}
put_charc(str[i], count);
i++;
}
}
void put_pointerc(void *pointer, size_t *count)
{
(*count) += 2;
write(STDOUT_FILENO, "0x", 2);
put_longhex((unsigned long)pointer, count);
}
void put_nbrc(int num, size_t *count)
{
char digit;
if (num == -2147483648)
{
putstrip("-2147483648", 1, count);
return ;
}
else if (num < 0)
{
put_charc('-', count);
num = -num;
}
if (num >= 10)
{
put_nbrc(num / 10, count);
num = num % 10;
}
digit = num + '0';
put_charc(digit, count);
}
void put_unbrc(unsigned int num, size_t *count)
{
char digit;
if (num >= 10)
{
put_unbrc(num / 10, count);
num = num % 10;
}
digit = num + '0';
put_charc(digit, count);
}
void put_hex(unsigned int num, unsigned char isLower, size_t *count)
{
char digit;
if (num >= 16)
{
put_hex(num / 16, isLower, count);
num = num % 16;
}
if (isLower)
digit = "0123456789abcdef"[num];
else
digit = "0123456789ABCDEF"[num];
put_charc(digit, count);
}