-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils2.c
81 lines (70 loc) · 1.71 KB
/
ft_printf_utils2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cdapurif <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/15 20:18:52 by cdapurif #+# #+# */
/* Updated: 2019/11/27 20:07:49 by cdapurif ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void place_precision(long long len)
{
int i;
char tab[(len > 0) ? len : 1];
i = -1;
if (len <= 0)
return ;
while (++i < len)
tab[i] = '0';
write(1, tab, len);
}
long long ft_nblen(long long nbr)
{
int i;
i = 1;
if (nbr < 0)
nbr *= -1;
while (nbr > 9)
{
nbr /= 10;
i++;
}
return (i);
}
void place_sep(t_struct *data, long long len)
{
int i;
char sep;
char tab[(len > 0) ? len : 1];
i = -1;
if (len <= 0)
return ;
sep = (data->flag & 1) ? '0' : ' ';
while (++i < len)
tab[i] = sep;
write(1, tab, len);
}
long long ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
unsigned int ft_atoi(const char *str)
{
unsigned int i;
unsigned int nb;
i = 0;
nb = 0;
while (str[i] >= '0' && str[i] <= '9')
{
nb = nb * 10 + str[i] - 48;
i++;
}
return (nb);
}