-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_apply_type.c
87 lines (79 loc) · 2.65 KB
/
ft_apply_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_apply_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: minkim3 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 13:53:46 by minkim3 #+# #+# */
/* Updated: 2023/01/21 20:47:56 by minkim3 ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_apply_int(t_options *string_info, int value)
{
char type;
char *string;
type = string_info->type;
if (value == 0 && type != 'c')
string_info->val_zero = 1;
if (type == 'd' || type == 'i')
ft_decimal_to_string(string_info, value);
else if (type == 'x' || type == 'X')
ft_decimal_to_hexadecimal(string_info, value);
else if (type == 'c')
{
if (value == 0)
string_info->val_null = 1;
string = ft_new_string(2);
if (string == NULL)
return (ft_malloc_error_void(string_info));
string[0] = (char)value;
string[1] = '\0';
string_info->value = string;
}
}
void ft_apply_unsigned_int(t_options *string_info, unsigned int value)
{
if (value == 0)
string_info->val_zero = 1;
string_info->value = ft_itoa_extension(value);
if (string_info->value == NULL)
return (ft_malloc_error_void(string_info));
}
void ft_apply_percent(t_options *string_info, int value)
{
char *string;
string = ft_new_string(2);
if (string == NULL)
return (ft_malloc_error_void(string_info));
string[0] = (char)value;
string[1] = '\0';
string_info->value = string;
}
void ft_apply_string(t_options *string_info, char *value)
{
if (!value)
{
string_info->value = ft_strdup("(null)");
if (string_info->value == NULL)
return (ft_malloc_error_void(string_info));
return ;
}
string_info->value = ft_strdup(value);
if (string_info->value == NULL)
return (ft_malloc_error_void(string_info));
}
void ft_apply_pointer(t_options *string_info, unsigned long long value)
{
if (!value)
{
string_info->value = ft_strdup("0x0");
if (string_info->value == NULL)
return (ft_malloc_error_void(string_info));
return ;
}
string_info->value = ft_pointer_to_lowercase_hexadecimal(value);
if (string_info->value == NULL)
return (ft_malloc_error_void(string_info));
}