-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_octal.c
61 lines (56 loc) · 2.13 KB
/
ft_print_octal.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_octal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/11 03:56:51 by ohachim #+# #+# */
/* Updated: 2019/05/26 06:49:16 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_conv_make(unsigned long long int convert)
{
char *oct_ray;
char *converted;
char *temp;
char *oct_char;
int out;
out = 0;
converted = ft_strnew(1);
oct_ray = ft_strjoin("", "01234567");
while (convert != 0 || out == 0)
{
oct_char = ft_make_s(1, oct_ray[convert % 8]);
temp = converted;
converted = ft_strjoin(oct_char, converted);
free(temp);
free(oct_char);
convert = convert / 8;
out++;
}
free(oct_ray);
return (converted);
}
void ft_print_octal(va_list arg, const char *format, t_rem *rems)
{
char *p_r;
char type_spec;
rems->fi_wi = ft_field_width(format, rems->cursor, arg);
rems->precision = ft_precision(format, rems->cursor, arg);
type_spec = ft_scan_flag(format, rems->cursor);
if (type_spec == 'l')
p_r = ft_conv_make((unsigned long int)va_arg(arg, unsigned long int));
else if (type_spec == 'L')
p_r = ft_conv_make(va_arg(arg, unsigned long long int));
else if (type_spec == 'H')
p_r = ft_conv_make((unsigned char)va_arg(arg, unsigned int));
else if (type_spec == 'h')
p_r = ft_conv_make((unsigned short int)va_arg(arg, unsigned int));
else
p_r = ft_conv_make((unsigned int)va_arg(arg, unsigned int));
p_r = ft_construct_s(p_r, format, rems, "0");
ft_putstr_rem(p_r, rems);
free(p_r);
}