maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atof.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_atof.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: rmikhayl <marvin@42.fr> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2024/05/15 14:50:17 by rmikhayl #+# #+# */
9
/* Updated: 2024/05/15 14:50:18 by rmikhayl ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
libft.h
"
14
15
double
ft_atof
(
const
char
*str)
16
{
17
double
res;
18
double
neg;
19
double
divider;
20
size_t
i;
21
22
divider = 0.1;
23
res = 0;
24
neg = 1;
25
i = -1;
26
while
(str[i] <
'0'
|| str[i] >
'9'
)
27
if
(str[i++] ==
'-'
)
28
neg = -1;
29
while
(str[i] >=
'0'
&& str[i] <=
'9'
)
30
{
31
res = res * 10 + str[i++] - 48;
32
}
33
if
(str[i] ==
'.'
|| str[i] ==
','
)
34
i++;
35
while
(str[i] >=
'0'
&& str[i] <=
'9'
)
36
{
37
res = res + (str[i] - 48) * divider;
38
divider /= 10;
39
i++;
40
}
41
return
(res * neg);
42
}
ft_atof
double ft_atof(const char *str)
Definition
ft_atof.c:15
libft.h
lib
libft
src
ft_atof.c
Generated by
1.9.8