-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_field_width.c
37 lines (34 loc) · 1.36 KB
/
ft_field_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_field_width.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/27 17:21:03 by ohachim #+# #+# */
/* Updated: 2019/05/26 05:54:17 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_field_width(const char *format, int csr, va_list arg)
{
int fi_wi;
csr--;
while (1)
{
while ((format[csr] < '0' || format[csr] > '9') && format[csr] != '%')
{
if (format[csr] == '*' && format[csr - 1] != '.')
return (va_arg(arg, int));
csr--;
}
while (format[csr] >= '0' && format[csr] <= '9')
csr--;
if (format[csr] != '.' || format[csr] == '%')
break ;
}
fi_wi = ft_atoi(&format[csr + 1]);
if (fi_wi < 0)
fi_wi = 0;
return (fi_wi);
}