-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
37 lines (35 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
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elraira- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/09 14:02:22 by elraira- #+# #+# */
/* Updated: 2021/08/16 18:19:47 by elraira- ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int res;
int sig;
sig = 1;
res = 0;
while (*str == ' ' || *str == '\n' || *str == '\t' || *str == '\r'
|| *str == '\f' || *str == '\v')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
{
sig = -sig;
}
str++;
}
while (*str >= 48 && *str <= 57)
{
res = (res * 10) + (*str - 48);
str++;
}
return (res * sig);
}