-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi_bonus.c
More file actions
36 lines (33 loc) · 1.3 KB
/
Copy pathft_atoi_bonus.c
File metadata and controls
36 lines (33 loc) · 1.3 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: obouizi <obouizi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/01 13:55:05 by obouizi #+# #+# */
/* Updated: 2024/12/05 20:46:35 by obouizi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf_bonus.h"
long ft_atoi(const char *str)
{
int i;
long nb;
nb = 0;
i = 0;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
i++;
while (str[i] == '-' || str[i] == '+'
|| (str[i] >= 9 && str[i] <= 13) || str[i] == 32 || str[i] == '0'
|| str[i] == '#')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
nb = nb * 10 + (str[i] - 48);
i++;
}
if (nb > 2147483647)
return (-1);
return (nb);
}