-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
52 lines (48 loc) · 1.46 KB
/
ft_printf_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomlulu <tomlulu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/09 14:31:40 by tomlulu #+# #+# */
/* Updated: 2018/01/23 11:41:10 by tmaraval ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_parser_read_int_upd_str_loop(char **format, int *ret)
{
while (ft_isdigit(**format))
{
if (*ret > INT_MAX)
*ret = -1;
else
{
*ret *= 10;
*ret += **format - '0';
}
(*format)++;
}
}
int ft_parser_read_int_upd_str(char **format)
{
int ret;
int isnega;
ret = 0;
isnega = FALSE;
if (**format == '-')
{
(*format)++;
ret = **format - '0';
isnega = TRUE;
}
else if (ft_isdigit(**format))
ret = **format - '0';
else
return (0);
(*format)++;
ft_parser_read_int_upd_str_loop(format, &ret);
if (isnega == TRUE)
ret *= -1;
return (ret);
}