diff options
| author | Dominik Kaiser | 2024-03-06 21:02:09 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2024-03-06 21:02:09 +0100 |
| commit | f861789c3e5e004395c1b7214757d5a83625d845 (patch) | |
| tree | 6eb15d263549018f639eb2b7fc5af6d621a39245 /ft_atoi.c | |
| download | libft-f861789c3e5e004395c1b7214757d5a83625d845.tar.gz libft-f861789c3e5e004395c1b7214757d5a83625d845.zip | |
Setup and current progress
Forgot to commit earlier...
Diffstat (limited to 'ft_atoi.c')
| -rw-r--r-- | ft_atoi.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ft_atoi.c b/ft_atoi.c new file mode 100644 index 0000000..6f7bd55 --- /dev/null +++ b/ft_atoi.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 16:25:27 by dkaiser #+# #+# */ +/* Updated: 2024/03/06 19:41:51 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(const char *str) +{ + int result; + int i; + int posneg; + + posneg = 1; + result = 0; + i = 0; + while (str[i] >= '\t' && str[i] <= '\r' || str[i] == ' ') + { + i++; + } + if (str[i] == '-') + { + posneg = -1; + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + result = 10 * result + str[i] - '0'; + i++; + } + return (result * posneg); +} + +/* #include <stdio.h> */ +/* #include <stdlib.h> */ +/* int main() { */ +/* char str[] = " -42eaeouai"; */ +/* printf("atoi: %d\n", atoi(str)); */ +/* printf("ft_atoi: %d\n", ft_atoi(str)); */ +/* } */ |
