-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_len_type.c
106 lines (97 loc) · 2.17 KB
/
set_len_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_len_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysonmez <ysonmez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/13 14:51:21 by ysonmez #+# #+# */
/* Updated: 2021/07/19 10:05:58 by ysonmez ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_count_digit(int n)
{
int i;
i = 1;
if (n == -2147483648)
return (11);
if (n < 0)
{
n = n * (-1);
i++;
}
while (n >= 10)
{
n /= 10;
i++;
}
return (i);
}
int ft_count_digit_unsint(unsigned int n)
{
int i;
i = 1;
while (n >= 10)
{
n /= 10;
i++;
}
return (i);
}
void ft_count_digit_hexa(unsigned long n, t_struct *data)
{
if (n >= 16)
ft_count_digit_hexa(n / 16, data);
(*data).alen++;
}
int ft_get_type(const char *str)
{
while (*str)
{
if (*str == 'd')
return (INTD);
else if (*str == 'i')
return (INTI);
else if (*str == 'c')
return (CHAR);
else if (*str == 's')
return (STR);
else if (*str == 'p')
return (PTR);
else if (*str == 'x')
return (LOWHEXA);
else if (*str == 'X')
return (UPHEXA);
else if (*str == 'u')
return (UNSINT);
else if (*str == '%')
return (PRCT);
str++;
}
return (-1);
}
int ft_get_chartype(t_struct *data)
{
int k;
k = (*data).type;
if (k == INTD)
return ('d');
else if (k == INTI)
return ('i');
else if (k == CHAR)
return ('c');
else if (k == STR)
return ('s');
else if (k == PTR)
return ('p');
else if (k == LOWHEXA)
return ('x');
else if (k == UPHEXA)
return ('X');
else if (k == UNSINT)
return ('u');
else if (k == PRCT)
return ('%');
return (-1);
}