-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_X.c
More file actions
57 lines (52 loc) · 1.53 KB
/
Copy pathft_printf_X.c
File metadata and controls
57 lines (52 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_X.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gloms <rbrendle@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 17:18:29 by gloms #+# #+# */
/* Updated: 2023/03/04 02:33:02 by gloms ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int len_nbr(unsigned int nbr)
{
int count;
count = 0;
if (!nbr)
count += 1;
while (nbr)
{
nbr /= 16;
count++;
}
return (count);
}
static int called_ft_printf_x(unsigned int nbr)
{
if (nbr < 10)
{
if (ft_putchar_pf(nbr + 48) < 0)
return (-2147483648);
}
if (nbr >= 16)
{
if (ft_printf_x(nbr / 16) < 0)
return (-2147483648);
if (ft_printf_x(nbr % 16) < 0)
return (-2147483648);
}
if (nbr >= 10 && nbr <= 15)
{
if (ft_putchar_pf(nbr + 55) < 0)
return (-2147483648);
}
return (1);
}
int ft_printf_x(unsigned int nbr)
{
if (called_ft_printf_x(nbr) < 0)
return (-2147483648);
return (len_nbr(nbr));
}