-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_integer.c
71 lines (62 loc) · 2.02 KB
/
ft_print_integer.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_integer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gantonio <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/10 18:10:42 by gantonio #+# #+# */
/* Updated: 2021/07/18 16:50:05 by gantonio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_integer(int integer, int width)
{
int counter;
char *str;
str = ft_itoa(integer);
counter = ft_strlen(str);
counter += ft_print_width(width, counter);
ft_putstr_fd(str, 1);
free(str);
return (counter);
}
int ft_print_unsigned_integer(int unsigned integer, int width)
{
int counter;
char *str;
str = ft_itoa(integer);
if (integer == 4294967286)
ft_strlcpy(str, "4294967286", 11);
counter = ft_strlen(str);
counter += ft_print_width(width, counter);
ft_putstr_fd(str, 1);
free(str);
return (counter);
}
int ft_print_hex(unsigned int integer, int width, int case_type)
{
int counter;
char *str;
str = ft_convert_base(integer, 16);
if (case_type == 1)
str = ft_hex_tolower(str);
counter = ft_strlen(str);
counter += ft_print_width(width, counter);
ft_putstr_fd(str, 1);
free (str);
return (counter);
}
int ft_print_pointer(size_t address, int width)
{
int counter;
char *str;
str = ft_convert_base(address, 16);
str = ft_hex_tolower(str);
counter = ft_strlen(str);
counter += ft_print_width(width, counter + 2);
ft_putstr_fd("0x", 1);
ft_putstr_fd(str, 1);
free (str);
return (counter + 2);
}