forked from ruv1nce/42-exam_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_hex.c
More file actions
61 lines (54 loc) · 1.48 KB
/
Copy pathprint_hex.c
File metadata and controls
61 lines (54 loc) · 1.48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dfonarev <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/14 17:13:19 by dfonarev #+# #+# */
/* Updated: 2019/01/31 19:57:53 by dfonarev ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_atoi(char *str)
{
int i;
int sum;
int posneg;
i = 0;
sum = 0;
posneg = 1;
while (str[i] <= ' ')
i++;
if (str[i] == '+')
i++;
else if (str[i] == '-')
{
posneg = -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
sum = sum * 10 + (str[i] - '0');
i++;
}
return (sum * posneg);
}
void ft_putchar(char c)
{
write(1, &c, 1);
}
void print_hex(int nb)
{
char *sym;
sym = "0123456789abcdef";
if (nb / 16 > 0)
print_hex(nb / 16);
ft_putchar(sym[nb % 16]);
}
int main(int argc, char **argv)
{
if (argc == 2)
print_hex(ft_atoi(argv[1]));
write(1, "\n", 1);
}