-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
48 lines (43 loc) · 1.45 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: tcakir-y <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/10 15:10:01 by tcakir-y #+# #+# */
/* Updated: 2024/10/16 19:33:31 by tcakir-y ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int result;
int sign;
int i;
result = 0;
sign = 1;
i = 0;
while ((nptr[i] >= '\t' && nptr[i] <= '\r') || nptr[i] == ' ')
i++;
if (nptr[i] == '-' || nptr[i] == '+')
{
if (nptr[i] == '-')
sign = -1;
i++;
}
while (nptr[i] && nptr[i] >= '0' && nptr[i] <= '9')
{
result = (result * 10) + (nptr[i] - '0');
i++;
}
return (result * sign);
}
//int main(void)
//{
// int result1 = ft_atoi("-1234");
// int result2 = atoi("-1234");
// printf("ft: %d\n", result1);
// printf("function: %d", result2);
// return (0);
//}