-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
47 lines (45 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgerdzhi <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 17:44:46 by rgerdzhi #+# #+# */
/* Updated: 2024/07/14 01:39:04 by rgerdzhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int result;
int sign;
result = 0;
sign = 1;
while (*nptr == ' ' || (*nptr >= '\t' && *nptr <= '\r'))
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign = -1;
nptr++;
}
while (*nptr >= '0' && *nptr <= '9')
{
result = result * 10 + (*nptr - '0');
nptr++;
}
return (result * sign);
}
/*
int main ()
{
int val;
char *str = NULL; //" -15yyh6abdc ";
val = ft_atoi(str);
printf("My value = %d\n", val);
val = atoi(str);
printf("Ctrl value = %d\n", val);
return(0);
}
*/