-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_write_arg.c
More file actions
73 lines (62 loc) · 1.8 KB
/
ft_write_arg.c
File metadata and controls
73 lines (62 loc) · 1.8 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_write_arg.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tdehne <tdehne@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/12 17:02:55 by tdehne #+# #+# */
/* Updated: 2022/04/30 15:07:07 by tdehne ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int write_c_i(va_list arg, char c)
{
int i;
i = va_arg(arg, int);
if (c == 'c')
{
c = (char) i;
return (write(1, &c, 1));
}
return (putnbr_count(i));
}
int write_s(va_list arg)
{
char *str;
str = va_arg(arg, char *);
if (!str)
return (write(1, "(null)", 6));
return (write(1, str, ft_strlen(str)));
}
int write_u(va_list arg)
{
unsigned int ui;
ui = va_arg(arg, unsigned int);
return (putuint_fd(ui, 1));
}
int write_p(va_list arg, char *base)
{
unsigned long long ptr;
int counter;
ptr = va_arg(arg, unsigned long long);
if (!ptr)
{
return (write(1, "0x0", 3));
}
counter = 0;
write(1, "0x", 2);
write_hex(ptr, base, &counter);
return (counter + 2);
}
int write_x_uppx(va_list arg, char *base)
{
unsigned int num;
int counter;
num = va_arg(arg, unsigned int);
if (num == 0)
return (write(1, "0", 1));
counter = 0;
write_hex(num, base, &counter);
return (counter);
}