-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printffunc.c
125 lines (114 loc) · 2.63 KB
/
ft_printffunc.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printffunc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ulyildiz <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 17:39:22 by ulyildiz #+# #+# */
/* Updated: 2023/11/05 13:56:46 by ulyildiz ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "ft_printf.h"
int ft_is_int(int i)
{
char *output;
int esc;
int check;
check = 0;
output = ft_itoa(i);
if (output == NULL)
return (-1);
esc = ft_strlen(output);
check = write(1, output, esc);
if (check == -1)
{
free(output);
return (-1);
}
free(output);
return (esc);
}
int ft_is_string(char *s)
{
int esc;
int check;
check = 0;
esc = 0;
if (s == NULL)
return (write(1, "(null)", 6));
while (s[esc] != '\0')
{
check = write (1, &(s[esc++]), 1);
if (check == -1)
return (-1);
}
return (esc);
}
int ft_is_hex(unsigned int hex, int to)
{
int esc;
int check;
check = 0;
esc = 0;
if (hex >= 16)
esc += ft_is_hex(hex / 16, to);
if (esc == -1)
return (-1);
if (to == 'x')
check = write (1, &"0123456789abcdef"[hex % 16], 1);
else if (to == 'X')
check = write (1, &"0123456789ABCDEF"[hex % 16], 1);
if (check == -1)
return (-1);
return (++esc);
}
int ft_is_address(unsigned long ul)
{
int esc;
int check;
check = 0;
esc = 0;
if (ul < 16)
esc += write (1, "0x", 2);
if (esc == -1)
return (-1);
if (ul >= 16)
{
check = ft_is_address(ul / 16);
if (check == -1)
return (-1);
esc += check;
check = write(1, &"0123456789abcdef"[ul % 16], 1);
if (check == -1)
return (-1);
return (++esc);
}
check = write(1, &"0123456789abcdef"[ul % 16], 1);
if (check == -1)
return (-1);
return (++esc);
}
int ft_is_unsigned(unsigned int un)
{
int esc;
int check;
check = 0;
esc = 0;
if (un >= 10)
{
check = ft_is_unsigned(un / 10);
if (check == -1)
return (-1);
esc += check;
check = write(1, &"0123456789"[un % 10], 1);
if (check == -1)
return (-1);
return (++esc);
}
check = write(1, &"0123456789"[un % 10], 1);
if (check == -1)
return (-1);
return (++esc);
}