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.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/c04/ex03/ft_atoi.c b/c04/ex03/ft_atoi.c
index 10f6b07..a26308e 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 10:23:20 by cacharle ### ########.fr */
+/* Updated: 2019/07/06 15:48:43 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,29 +31,22 @@ int ft_atoi(char *str)
int j;
while (*str == ' ' || *str == '\t' || *str == '\n'
- || *str == '\v' || *str == '\f' || *str == '\r')
+ || *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')
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++;
- }
+ nb += pow10(--i) * (str[j++] - '0');
if (is_negative)
nb = -nb;
return (nb);