-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_numbers.c
More file actions
79 lines (70 loc) · 1.94 KB
/
ft_numbers.c
File metadata and controls
79 lines (70 loc) · 1.94 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marcrodr < marcrodr@student.42sp.org.br +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/07 22:14:48 by marcrodr #+# #+# */
/* Updated: 2022/02/14 10:06:53 by marcrodr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int print_c(char *str, int arg)
{
write(1, &arg, 1);
str++;
return (1);
}
int print_percent(char *str)
{
write(1, "%", 1);
str++;
return (1);
}
int print_s(char *str, char *arg)
{
int len;
if (arg == NULL)
{
ft_putstr_fd("(null)", 1);
return (6);
}
len = ft_strlen(arg);
ft_putstr_fd(arg, 1);
str++;
return (len);
}
int print_d(char *str, int arg)
{
char *number_str;
int len;
if (*str == 'u')
number_str = ft_ullitoa_base((unsigned int) arg, DECIMAL);
else
number_str = ft_itoa(arg);
len = ft_strlen(number_str);
ft_putstr_fd(number_str, 1);
free(number_str);
return (len);
}
int print_x(char *str, unsigned long int arg)
{
char *number_str;
int width;
width = 0;
if (*str == 'p')
{
width += 2;
ft_putstr_fd("0x", 1);
number_str = ft_ullitoa_base(arg, HEXALOWER);
}
else if (*str == 'X')
number_str = ft_ullitoa_base((unsigned int) arg, HEXAUPPER);
else
number_str = ft_ullitoa_base((unsigned int) arg, HEXALOWER);
ft_putstr_fd(number_str, 1);
width += ft_strlen(number_str);
free(number_str);
return (width);
}