-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_print_csp.c
77 lines (69 loc) · 1.8 KB
/
ft_printf_print_csp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_print_csp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lburkins <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 15:37:29 by lburkins #+# #+# */
/* Updated: 2023/12/01 11:51:33 by lburkins ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int printchar(int c, int *check)
{
if (*check == -1)
return (0);
if (write(1, &c, 1) == -1)
{
*check = -1;
return (0);
}
return (1);
}
int printstr(const char *str, int *check)
{
int count;
int i;
count = 0;
i = 0;
if (!str)
{
count += printstr("(null)", check);
return (count);
}
while (str[i] != '\0')
{
count += printchar(str[count], check);
i++;
}
return (count);
}
int printptr(unsigned long int ptr, int *check)
{
int count;
count = 0;
if (!ptr)
count += printstr("0x0", check);
else
{
count += printstr("0x", check);
count += printnbr_ptr(ptr, check);
}
return (count);
}
int printnbr_ptr(unsigned long int n, int *check)
{
int count;
char *symbols;
symbols = "0123456789abcdef";
count = 0;
if (n > 15)
{
count += printnbr_ptr((n / 16), check);
count += printchar(symbols[n % 16], check);
}
else
count += printchar(symbols[n], check);
return (count);
}