-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
31 lines (28 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeonhkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/08 15:25:18 by yeonhkim #+# #+# */
/* Updated: 2022/07/23 00:08:37 by yeonhkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int num;
char sign;
sign = 1;
while (*str == '\t' || *str == '\n' || *str == '\v' || *str == '\f'\
|| *str == '\r' || *str == ' ')
str++;
if (*str == '+' || *str == '-')
if (*str++ == '-')
sign = -1;
num = 0;
while ('0' <= *str && *str <= '9')
num = (num * 10) + (*str++ - '0');
return (sign * num);
}