-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_utils_nbr.c
More file actions
69 lines (62 loc) · 1.79 KB
/
ft_utils_nbr.c
File metadata and controls
69 lines (62 loc) · 1.79 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils_nbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ilnassi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/14 17:29:02 by ilnassi #+# #+# */
/* Updated: 2025/01/16 14:02:10 by ilnassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbr(int nb)
{
char digit;
int char_count;
char_count = 0;
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
return (11);
}
if (nb < 0)
{
write(1, "-", 1);
char_count++;
nb = -nb;
}
if (nb >= 10)
char_count += ft_putnbr(nb / 10);
digit = (nb % 10) + '0';
write(1, &digit, 1);
char_count++;
return (char_count);
}
int ft_putnbr_unsigned(unsigned int nb)
{
char digit;
int char_count;
char_count = 0;
if (nb >= 10)
char_count += ft_putnbr_unsigned(nb / 10);
digit = (nb % 10) + '0';
write(1, &digit, 1);
char_count++;
return (char_count);
}
int ft_print_hexa(unsigned long long nb, int uppercase)
{
char *hex;
int char_count;
char_count = 0;
if (uppercase)
hex = "0123456789ABCDEF";
else
hex = "0123456789abcdef";
if (nb >= 16)
char_count += ft_print_hexa(nb / 16, uppercase);
write(1, &hex[nb % 16], 1);
char_count++;
return (char_count);
}