-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintxsc.c
More file actions
91 lines (83 loc) · 1.72 KB
/
printxsc.c
File metadata and controls
91 lines (83 loc) · 1.72 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
79
80
81
82
83
84
85
86
87
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printxsc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaljaber <aaljaber@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/07 20:12:56 by aaljaber #+# #+# */
/* Updated: 2021/11/10 21:08:22 by aaljaber ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void puthex(unsigned int h, int type)
{
if (h > 15)
{
puthex(h / 16, type);
puthex(h % 16, type);
}
else
{
if (h <= 9)
printchar(h + '0');
else
{
if (type == 1)
printchar(h - 10 + 'a');
if (type == 2)
printchar(h - 10 + 'A');
}
}
}
static int hexlen(unsigned int h)
{
int len;
len = 0;
while (h != 0)
{
len++;
h = h / 16;
}
return (len);
}
int printhex(unsigned int h, int type)
{
if (h == 0)
{
printchar('0');
return (1);
}
else
{
puthex(h, type);
return (hexlen(h));
}
}
int printstr(char *string)
{
int i;
char *n;
i = 0;
n = "(null)";
if (string == NULL)
{
while (n[i])
{
write(1, &n[i], 1);
i++;
}
return (i);
}
while (string[i])
{
write(1, &string[i], 1);
i++;
}
return (i);
}
int printchar(int c)
{
write (1, &c, 1);
return (1);
}