-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_type.c
73 lines (64 loc) · 2.04 KB
/
print_type.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysonmez <ysonmez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/13 16:25:50 by ysonmez #+# #+# */
/* Updated: 2021/07/19 10:30:17 by ysonmez ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putcharr_fd(char c, int fd)
{
write(fd, &c, 1);
}
void ft_puthexa_fd(unsigned int n, t_struct *data, int fd)
{
char *hxbase;
if ((*data).argunsint == 0 && (*data).prec == 0)
return ;
if ((*data).type == UPHEXA)
hxbase = ft_strdup("0123456789ABCDEF");
else
hxbase = ft_strdup("0123456789abcdef");
if (n >= 16)
ft_puthexa_fd(n / 16, data, fd);
ft_putchar_fd(hxbase[n % 16], data, fd);
free(hxbase);
}
void ft_putunsint_fd(unsigned int n, t_struct *data, int fd)
{
if ((*data).argunsint == 0 && (*data).prec == 0)
return ;
if (n >= 10)
ft_putunsint_fd(n / 10, data, fd);
ft_putchar_fd((n % 10) + 48, data, fd);
}
void ft_putunslong_fd(unsigned long n, t_struct *data, int fd)
{
char *hxbase;
if ((*data).argptr == 0 && (*data).prec == 0)
return ;
hxbase = ft_strdup("0123456789abcdef");
if (n >= 16)
ft_putunslong_fd(n / 16, data, fd);
ft_putchar_fd(hxbase[n % 16], data, fd);
free(hxbase);
}
int ft_printf_atoi(const char *str)
{
size_t i;
int result;
i = 1;
result = 0;
while (str[i] == '+')
i++;
while (str[i] >= 48 && str[i] <= 57)
{
result = result * 10 + ((str[i] - 48) % 10);
i++;
}
return (result);
}