-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils2.c
90 lines (82 loc) · 1.33 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
82
83
84
85
86
87
88
89
90
#include "ft_printf.h"
char *itoa_printf(intmax_t n)
{
char *str;
int num_len;
num_len = ft_intlen(n);
if (!(str = ft_calloc((num_len + 1), sizeof(char))))
return (NULL);
str[num_len] = '\0';
while (num_len)
{
if (n < 0)
{
str[--num_len] = -(n % 10) + 48;
n = n / 10;
n = -n;
}
else
{
str[--num_len] = n % 10 + 48;
n = n / 10;
}
}
return (str);
}
int ft_atoi_printf(char *str, int *i)
{
int atoi;
atoi = 0;
while (str[*i] >= '0' && str[*i] <= '9')
{
atoi = atoi * 10 + str[*i] - 48;
(*i)++;
}
(*i)--;
return (atoi);
}
char *ft_strdup_l(char *s, t_tab *tab)
{
char *str;
int i;
int len;
i = 0;
len = ft_strlen(s);
if (tab->precision && tab->precision_width < len)
len = tab->precision_width;
if (!(str = ft_calloc(len + 1, sizeof(char))))
return (NULL);
while (i < len)
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
void ft_set_precision(t_tab *tab)
{
tab->precision = 1;
tab->precision_parsing = 1;
tab->precision_width = 0;
}
void ft_reset_flags(t_tab *tab)
{
tab->width = 0;
tab->precision = 0;
tab->precision_width = 0;
tab->precision_parsing = 0;
tab->conv = 0;
tab->minus = 0;
tab->zero = 0;
tab->plus = 0;
tab->space = 0;
tab->sharp = 0;
tab->len = 0;
tab->sp_len = 0;
tab->is_int = 0;
tab->h_count = 0;
tab->l_count = 0;
tab->n = 0;
tab->u = 0;
}