-
Notifications
You must be signed in to change notification settings - Fork 0
/
choose_type_di.c
66 lines (59 loc) · 1.93 KB
/
choose_type_di.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* choose_type_di.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhallama <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/03 14:44:52 by jhallama #+# #+# */
/* Updated: 2020/01/08 11:55:20 by jhallama ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include "libft/libft.h"
static char *choose_more2(char *s, t_fields *fields)
{
t_length_type_di length;
if (fields->l != 1 && fields->ll != 1 && fields->h != 1 && fields->hh != 1)
{
length.int_n = va_arg(fields->ap, int);
s = ft_itoa(length.int_n);
}
return (s);
}
static char *choose_more(char *s, t_fields *fields)
{
t_length_type_di length;
if (fields->h == 1)
{
length.short_n = va_arg(fields->ap, int);
s = ft_itoa(length.short_n);
}
else if (fields->hh == 1)
{
length.signed_char_n = va_arg(fields->ap, int);
s = ft_itoa(length.signed_char_n);
}
s = choose_more2(s, fields);
return (s);
}
char *choose_type_di(t_fields *fields)
{
char *s;
t_length_type_di length;
s = NULL;
if (fields->l == 1)
{
length.long_n = va_arg(fields->ap, long);
s = ft_itoa_ll(length.long_n);
}
else if (fields->ll == 1)
{
length.long_long_n = va_arg(fields->ap, long long);
s = ft_itoa_ll(length.long_long_n);
}
s = choose_more(s, fields);
if (ft_strcmp(s, "0") == 0 && fields->precision == 0)
s[0] = '\0';
return (s);
}