diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
| commit | 8ec5431354bdb582455e8c32758098c5a0fdada2 (patch) | |
| tree | 480c68814f822439850029df0e0249a2cafb8177 /exam_final/rendu/ft_atoi | |
| parent | 475449dd4b1f3308bac6f72c34d87812216a0738 (diff) | |
| download | piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.gz piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.bz2 piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.zip | |
exam final
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); +} |
