-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_width.c
59 lines (53 loc) · 1.68 KB
/
ft_width.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_width.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccastill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/19 05:50:04 by ccastill #+# #+# */
/* Updated: 2020/07/19 01:12:38 by ccastill ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_strlen_str(const char *s, int l)
{
size_t count;
count = 0;
while (s[l] >= '0' && s[l] <= '9')
{
count++;
l++;
}
return (count);
}
void ft_asterisk(t_list_printf *next)
{
next->width = va_arg(next->args, int);
if (next->width < 0)
{
next->width *= -1;
next->ar_neg = 1;
}
next->len++;
}
int ft_width(const char *s, t_list_printf *next)
{
char *new;
next->ar_neg = 0;
if (next->flags == '-' || next->flags == '0' || next->flags == 1 ||
next->flags == '*')
{
if (s[next->len] >= '0' && s[next->len] <= '9')
{
new = ft_substr(s, next->len, ft_strlen_str(s, next->len));
next->width = ft_atoi(new);
free(new);
new = NULL;
next->len += ft_strlen_str(s, next->len);
}
else if (s[next->len] == '*')
ft_asterisk(next);
}
return (next->width);
}