-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_specifier2.c
More file actions
78 lines (72 loc) · 1.79 KB
/
ft_specifier2.c
File metadata and controls
78 lines (72 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
70
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_specifier2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shkaruna <shkaruna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 16:08:19 by shkaruna #+# #+# */
/* Updated: 2024/01/25 16:37:18 by shkaruna ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar(char c, int *count)
{
write(1, &c, 1);
(*count)++;
}
void ft_putnbr(int n, int *count)
{
if (n == -2147483648)
{
write(1, "-2147483648", 11);
(*count) += 11;
return ;
}
else if (n < 0)
{
ft_putchar('-', count);
ft_putnbr(-n, count);
}
else if (n >= 10)
{
ft_putnbr(n / 10, count);
ft_putchar(n % 10 + '0', count);
}
else
ft_putchar(n + '0', count);
}
void ft_unsignednbr(unsigned int n, int *count)
{
if (n >= 10)
{
ft_unsignednbr(n / 10, count);
}
ft_putchar((n % 10) + '0', count);
}
void ft_hexadecimal(unsigned int n, int *count, char x_or_X)
{
char str[25];
char *num_base;
int i;
if (x_or_X == 'x')
num_base = "0123456789abcdef";
else
num_base = "0123456789ABCDEF";
i = 0;
if (n == 0)
{
ft_putchar('0', count);
return ;
}
while (n != 0)
{
str[i] = num_base[n % 16];
n = n / 16;
i++;
}
while (i--)
{
ft_putchar(str[i], count);
}
}