mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-22 20:11:44 +00:00
fixed atoi / atof
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1631 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
1592df5945
commit
673a336982
2 changed files with 9 additions and 0 deletions
|
@ -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 <string.h>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue