From 252c83800b0b0d038212c916a4e48f2ab0060f4c Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 5 Dec 2022 13:57:45 +0100 Subject: [PATCH] add private atoi function --- atoi.c | 23 +++++++++++++++++++++++ atoi.h | 8 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 atoi.c create mode 100644 atoi.h diff --git a/atoi.c b/atoi.c new file mode 100644 index 0000000..fd3fedd --- /dev/null +++ b/atoi.c @@ -0,0 +1,23 @@ +#include "atoi.h" + +int myatoi (char *str) +{ + int i = 0; + int s = 1; + + if (*str == '-') { + s = 0; + str++; + } + + while (*str != 0) { + if ((*str <'0') || (*str > '9')) { + return 0; + } + i = i * 10 + (int)(*(str++) - '0'); + } + + return (s) ? i : -i; +} + +/* vim: set ts=4 sw=4 et */ diff --git a/atoi.h b/atoi.h new file mode 100644 index 0000000..74d58c3 --- /dev/null +++ b/atoi.h @@ -0,0 +1,8 @@ +#ifndef __ATOI_H__ +#define __ATOI_H__ + +int myatoi (char *str); + +#endif /* __ATOI_H__ */ + +/* vim: set ts=4 sw=4 et */ -- 2.30.2