-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_puthex.c
More file actions
49 lines (44 loc) · 1.47 KB
/
ft_puthex.c
File metadata and controls
49 lines (44 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iuslu <iuslu@student.42kocaeli.com.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/16 10:14:59 by iuslu #+# #+# */
/* Updated: 2026/02/18 12:42:48 by iuslu ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
static int ft_hexcal(unsigned long n, char c)
{
char *hexbasel;
char *hexbaseu;
int counter;
counter = 0;
hexbasel = "0123456789abcdef";
hexbaseu = "0123456789ABCDEF";
if (c == 'x' && n > 0)
{
counter += ft_hexcal(n / 16, c);
counter += write(1, &hexbasel[n % 16], 1);
}
else if (c == 'X' && n > 0)
{
counter += ft_hexcal(n / 16, c);
counter += write(1, &hexbaseu[n % 16], 1);
}
return (counter);
}
int ft_puthex(unsigned long n, char c)
{
int counter;
counter = 0;
if (n == 0)
{
write(1, "0", 1);
return (1);
}
counter = ft_hexcal(n, c);
return (counter);
}