-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
37 lines (34 loc) · 1.23 KB
/
ft_atoi.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_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wtaylor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/06 19:05:59 by wtaylor #+# #+# */
/* Updated: 2020/11/08 14:55:19 by wtaylor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *s)
{
int i;
int minus;
i = 0;
minus = 1;
while (*s && (*s == ' ' || *s == '\n' || *s == '\t' ||
*s == '\v' || *s == '\f' || *s == '\r'))
s++;
if (*s == '-' || *s == '+')
{
if (*s == '-')
minus = -1;
s++;
}
while (*s && *s >= '0' && *s <= '9')
{
i *= 10;
i += (*s++ - '0');
}
return (i * minus);
}