-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_control.c
More file actions
93 lines (82 loc) · 2.01 KB
/
ft_control.c
File metadata and controls
93 lines (82 loc) · 2.01 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_control.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: algungor <algungor@student.42istanbul.com.t+#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/15 02:19:05 by algungor #+# #+# */
/* Updated: 2026/03/13 22:12:42 by algungor ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_x_control(unsigned long i, char c)
{
unsigned int count;
count = 0;
if (i == 0)
return (ft_putchar('0'));
if (i >= 16)
count += ft_x_control(i / 16, c);
if (c == 'X')
count += write(1, &"0123456789ABCDEF"[i % 16], 1);
else
count += write(1, &"0123456789abcdef"[i % 16], 1);
return (count);
}
int ft_p_control(void *p, char c)
{
unsigned long i;
int count;
(void)c;
i = (unsigned long)p;
if (!p)
return (write(1, "(nil)", 5));
count = write(1, "0x", 2);
count += ft_x_control(i, 'x');
return (count);
}
int ft_putstr(char *s)
{
int i;
i = 0;
if (!s)
return (write(1, "(null)", 6));
while (s[i])
{
ft_putchar(s[i]);
i++;
}
return (i);
}
int ft_putnbr(int n)
{
long total;
long s;
long len;
len = 0;
s = n;
if (s < 0)
{
len += write(1, "-", 1);
s = -s;
}
if (s > 9)
{
len += ft_putnbr(s / 10);
total = (s % 10) + 48;
len += ft_putchar(total);
}
else if (s <= 9)
len += ft_putchar(s + '0');
return (len);
}
int ft_unnbr(unsigned int n)
{
int count;
count = 0;
if (n >= 10)
count += ft_unnbr(n / 10);
count += ft_putchar((n % 10) + '0');
return (count);
}