-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
35 lines (32 loc) · 1.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajakob <ajakob@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 14:24:15 by ajakob #+# #+# */
/* Updated: 2022/11/30 15:05:43 by ajakob ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int res;
int sign;
res = 0;
sign = 1;
while (*str == '\t' || *str == '\n' || *str == '\f'
|| *str == '\v' || *str == '\r' || *str == ' ')
str++;
if (*str == '-')
sign = -1;
if (*str == '-' || *str == '+')
str++;
while (*str >= 48 && *str <= 57)
{
res = res * 10 + (*str - 48);
str++;
}
return (res * sign);
}