-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printutils.c
83 lines (74 loc) · 1.8 KB
/
ft_printutils.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
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printutils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhiguera <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/31 19:27:13 by mhiguera #+# #+# */
/* Updated: 2023/07/05 14:45:00 by mhiguera ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <stdio.h>
long ft_pointertohexa(unsigned long num)
{
int len;
char *str;
str = "0123456789abcdef";
len = 0;
if (num >= 16)
len = len + ft_pointertohexa(num / 16);
len = len + write(1, str + (num % 16), 1);
return (len);
}
int ft_printstr(char *str)
{
int i;
i = 0;
if (str == NULL)
str = "(null)";
while (str[i])
{
write (1, &str[i], 1);
i++;
}
return (i);
}
int ft_printpointer(unsigned long ptr)
{
int len;
len = 0;
ft_printchar('0');
ft_printchar('x');
len = ft_pointertohexa(ptr) + 2;
return (len);
}
int ft_printnbr(int num)
{
int i;
i = 0;
if (num < 0)
{
if (num == -2147483648)
{
i = i + write (1, "-2", 2);
num = 147483648;
}
else
{
ft_printchar('-');
num = num * -1;
i++;
}
}
if (num > 9)
i = i + ft_printnbr(num / 10);
i = i + ft_printchar((num % 10) + '0');
return (i);
}
int ft_printpercent(void)
{
write (1, "%", 1);
return (1);
}