-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
49 lines (45 loc) · 1.33 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
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davgalle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/20 13:52:43 by davgalle #+# #+# */
/* Updated: 2023/07/22 12:10:34 by davgalle ### ########.fr */
/* */
/* ************************************************************************** */
#include<string.h>
#include<stdio.h>
#include<unistd.h>
int ft_atoi(char *str)
{
int i;
int j;
int z;
i = 0;
j = 0;
z = 0;
while (str[i] == ' ' || str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
j++;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
z = z * 10;
z = z + str[i] - '0';
i++;
}
if (j % 2 != 0)
z = z * -1;
return (z);
}
/*
int main(void)
{
char str[]=" ---+--+1234ab567";
printf("%d", ft_atoi(str));
return 0;
}*/