-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
48 lines (43 loc) · 1.38 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
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hecmarti <hecmarti@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/16 15:33:58 by hecmarti #+# #+# */
/* Updated: 2023/10/18 14:59:09 by hecmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include<stdio.h>
#include<stdlib.h>
int ft_atoi(const char *str)
{
int count;
int val;
int aux;
count = 0;
val = 1;
aux = 0;
while (str[count] == ' ' || (str[count] >= 9 && str[count] <= 13))
count++;
if (str[count] == '-' || str[count] == '+')
{
if (str[count] == '-')
val = -1;
count++;
}
while (str[count] >= '0' && str[count] <= '9')
{
aux = aux * 10 + (str[count] - '0');
count++;
}
return (aux * val);
}
/*
int main(void)
{
const char str[] = "123";
printf("%d\n", ft_atoi(str));
}
*/