From 673a336982ab1980c731ccb828f2b57003587b32 Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 30 Nov 2005 01:02:10 +0000 Subject: [PATCH] fixed atoi / atof git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1631 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- plugins/plugin.h | 3 +++ plugins/qvm_api.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/plugin.h b/plugins/plugin.h index 9fe599424..110fa7796 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -24,6 +24,9 @@ char *strstr(char *str, const char *sub); void strlcpy(char *d, const char *s, int n); char *strchr(char *str, char sub); +float atof(char *str); +int atoi(char *str); + #else #include diff --git a/plugins/qvm_api.c b/plugins/qvm_api.c index 1a621ca24..dfa732c93 100644 --- a/plugins/qvm_api.c +++ b/plugins/qvm_api.c @@ -419,6 +419,7 @@ int atoi(char *str) sign = -1; str++; } + else sign = 1; if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { @@ -435,9 +436,11 @@ int atoi(char *str) else if (*str >= 'A' && *str <= 'A'+base-10) num = num*base + (*str - 'A')+10; else break; //bad char + str++; } return num*sign; } + float atof(char *str) { int sign; @@ -452,12 +455,14 @@ float atof(char *str) sign = -1; str++; } + else sign = 1; while(1) {//each time we find a new digit, increase the value of the previous digets by a factor of ten, and add the new if (*str >= '0' && *str <= '9') num = num*10 + (*str - '0'); else break; //bad char + str++; } if (*str == '.') { //each time we find a new digit, decrease the value of the following digits. @@ -469,6 +474,7 @@ float atof(char *str) num = num + (*str - '0')*unit; } else break; //bad char + str++; } } return num*sign;