diff options
Diffstat (limited to 'exam_final/rendu/ft_atoi')
| -rwxr-xr-x | exam_final/rendu/ft_atoi/ft_atoi.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/exam_final/rendu/ft_atoi/ft_atoi.c b/exam_final/rendu/ft_atoi/ft_atoi.c new file mode 100755 index 0000000..2f125bf --- /dev/null +++ b/exam_final/rendu/ft_atoi/ft_atoi.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 11:11:42 by exam #+# #+# */ +/* Updated: 2019/07/26 11:32:51 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(const char *str) +{ + int nb; + int is_negative; + + while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' + || *str == '\v' || *str == '\f'|| *str == '\r') + str++; + is_negative = 0; + if (*str == '+' || *str == '-') + { + if (*str == '-') + is_negative = 1; + str++; + } + nb = 0; + while (*str >= '0' && *str <= '9') + { + nb *= 10; + nb += *str - '0'; + str++; + } + if (is_negative) + nb = -nb; + return (nb); +} |
