aboutsummaryrefslogtreecommitdiff
path: root/c04/ex03/ft_atoi.c
diff options
context:
space:
mode:
Diffstat (limited to 'c04/ex03/ft_atoi.c')
-rw-r--r--c04/ex03/ft_atoi.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/c04/ex03/ft_atoi.c b/c04/ex03/ft_atoi.c
index 0d4247b..10f6b07 100644
--- a/c04/ex03/ft_atoi.c
+++ b/c04/ex03/ft_atoi.c
@@ -6,7 +6,7 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/06 07:31:38 by cacharle #+# #+# */
-/* Updated: 2019/07/06 08:36:47 by cacharle ### ########.fr */
+/* Updated: 2019/07/06 10:23:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,21 +28,31 @@ int ft_atoi(char *str)
int is_negative;
int nb;
int i;
+ int j;
while (*str == ' ' || *str == '\t' || *str == '\n'
|| *str == '\v' || *str == '\f' || *str == '\r')
str++;
+ is_negative = 0;
+ /*printf("> %s\n", str);*/
while (*str == '-' || *str == '+')
{
if (*str == '-')
is_negative = !is_negative;
str++;
}
+ /*printf("> %s\n", str);*/
+ nb = 0;
i = 0;
while (str[i] >= '0' && str[i] <= '9')
- {
- nb += pow10(i) * (str[i] - '0');
i++;
+ j = 0;
+ while (str[j] >= '0' && str[j] <= '9')
+ {
+ /*printf("%d i, %d nb\n", i, nb);*/
+ i--;
+ nb += pow10(i) * (str[j] - '0');
+ j++;
}
if (is_negative)
nb = -nb;