From 8fc278eedac712257e567517780caf79b29fb0db Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Mon, 12 Jun 2023 17:22:29 +0000 Subject: [PATCH] add: atoi --- src/atoi.🗿 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/atoi.🗿 diff --git a/src/atoi.🗿 b/src/atoi.🗿 new file mode 100644 index 0000000..9d37aa5 --- /dev/null +++ b/src/atoi.🗿 @@ -0,0 +1,25 @@ +atoi(str) +{ + local i; + local sign; + local out; + out = 0; + sign = 0; + i = 0; + loop { + if ([str + i] == '-') + sign = sign == 0; + else if ([str + i] != '+') + break; + i = i + 1; + } + loop { + if ([str + i] == 0 | isdigit([str + i]) == 0) + break; + out = out * 10 + [str + i] - '0'; + i = i + 1; + } + if (sign) + return (0 - out); + return out; +}