maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atof.c File Reference
#include "libft.h"
Include dependency graph for ft_atof.c:

Go to the source code of this file.

Functions

double ft_atof (const char *str)
 

Function Documentation

◆ ft_atof()

double ft_atof ( const char *  str)

Definition at line 15 of file ft_atof.c.

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}