-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong_atoi.c
38 lines (35 loc) · 1.22 KB
/
long_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
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* long_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rdragan <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/24 14:03:29 by rdragan #+# #+# */
/* Updated: 2023/04/25 19:54:23 by rdragan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long long long_atoi(char *str)
{
long long res;
int sign;
int i;
res = 0;
sign = 1;
i = 0;
while (str[i] == ' ' || str[i] == '\t')
i++;
if (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
sign = -1;
i++;
}
while (ft_isdigit(str[i]))
{
res = res * 10 + str[i] - '0';
i++;
}
return (res * sign);
}