diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-10-11 22:19:00 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-10-11 22:19:00 +0200 |
| commit | 73c2b00a10c5786ddeeacc915e233fd4df1c9321 (patch) | |
| tree | e299ea4e8ac161b2b21170172ff8f182c1c3fe1a /rushs/tinyprintf/my_atoi_base | |
| parent | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (diff) | |
fix: evalexpr & tinyprintf contenaient toute la piscine
Diffstat (limited to 'rushs/tinyprintf/my_atoi_base')
| -rw-r--r-- | rushs/tinyprintf/my_atoi_base/my_atoi_base.c | 86 | ||||
| -rw-r--r-- | rushs/tinyprintf/my_atoi_base/my_atoi_base.h | 8 |
2 files changed, 0 insertions, 94 deletions
diff --git a/rushs/tinyprintf/my_atoi_base/my_atoi_base.c b/rushs/tinyprintf/my_atoi_base/my_atoi_base.c deleted file mode 100644 index 46b4560..0000000 --- a/rushs/tinyprintf/my_atoi_base/my_atoi_base.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "my_atoi_base.h" - -int val_in_base(char c, const char *base) -{ - size_t i; - for (i = 0; base[i] && base[i] != c; i++) - { - continue; - } - - if (base[i]) - { - return i; - } - - return -1; -} - -int base_size(const char *base) -{ - int res; - for (res = 0; base[res]; res++) - { - continue; - } - return res; -} - -int my_atoi_base(const char *str, const char *base) -{ - int res = 0; - - // str error check - if (str == NULL || *str == '0') - { - return 0; - } - - // trim whitespaces - for (; *str && *str == ' '; str++) - { - continue; - } - - // move to end of str - size_t l; - for (l = 0; str[l]; l++) - { - continue; - } - l--; - - // prepare for calculations - int b = base_size(base); - int factor = 1; - - // actual conversion of up to the second element of str (potential sign) - for (; l > 0; l--) - { - int val = val_in_base(str[l], base); - if (val == -1) - { - return 0; - } - res += val * factor; - - factor *= b; - } - - // l should be 0 by now - if (str[l] == '-') - { - return -res; - } - else if (str[l] != '+') - { - int val = val_in_base(str[l], base); - if (val == -1) - { - return 0; - } - return res + val * factor; - } - - return res; -} diff --git a/rushs/tinyprintf/my_atoi_base/my_atoi_base.h b/rushs/tinyprintf/my_atoi_base/my_atoi_base.h deleted file mode 100644 index 296ae23..0000000 --- a/rushs/tinyprintf/my_atoi_base/my_atoi_base.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MY_ATOI_BASE_H -#define MY_ATOI_BASE_H - -#include <stddef.h> - -int my_atoi_base(const char *str, const char *base); - -#endif /* ! MY_ATOI_BASE_H */ |
