-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_precision.c
33 lines (30 loc) · 1.34 KB
/
ft_precision.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_precision.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/26 06:15:43 by ohachim #+# #+# */
/* Updated: 2019/05/26 06:15:55 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_precision(const char *format, int cursor, va_list arg)
{
int precision;
precision = 0;
while (format[cursor] != '.' && format[cursor] != '%')
{
if (format[cursor] == '*' && format[cursor - 1] == '.')
return (va_arg(arg, int));
cursor--;
}
if (format[cursor] == '%')
return (0);
if (format[cursor + 1] >= '0' && format[cursor] <= '9')
precision = ft_atoi(&format[cursor + 1]);
if (precision < 0)
precision = -1;
return (precision);
}