-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
41 lines (38 loc) · 1.25 KB
/
ft_atoi.c
File metadata and controls
41 lines (38 loc) · 1.25 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
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gudaniel <gudaniel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:54:48 by gudaniel #+# #+# */
/* Updated: 2024/04/09 13:54:54 by gudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *s)
{
int sign;
long r;
r = 0;
sign = 1;
while (*s == 32 || (*s >= 9 && *s <= 13))
s++;
if (*s == '-' || *s == '+')
{
if (*s == '-')
sign = -1;
s++;
}
while (*s >= '0' && *s <= '9')
{
r = r * 10 + *s - '0';
s++;
}
return (sign * (int)r);
}
/* int main()
{
printf("%d", ft_atoi(" -1234ab56"));
return(0);
} */